home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / graphics / display / mpega / src / mpega_decode_asm.a < prev    next >
Encoding:
Text File  |  1997-11-20  |  67.0 KB  |  2,258 lines

  1. ;------------------------------------------------------------------------------
  2. ;
  3. ;    Fichier :    mpega_decode_asm.a
  4. ;
  5. ;    Auteur  :    Stéphane TAVENARD
  6. ;
  7. ;    $VER:   mpega_decode_asm.a  1.0  (23/06/1995)
  8. ;
  9. ;    (C) Copyright 1995 Stéphane TAVENARD
  10. ;    All Rights Reserved
  11. ;
  12. ;    #Rev|   Date   |               Comment
  13. ;    ----|----------|--------------------------------------------------------
  14. ;    0     |11/04/1995| Initial revision                       ST
  15. ;    1     |18/06/1995| Use of fast cosine transform for synthesis filter    ST
  16. ;    2     |23/06/1995| Aminet release                       ST
  17. ;
  18. ;    ------------------------------------------------------------------------
  19. ;
  20. ;    Routines pour le decodage MPEG audio (optimisées)
  21. ;
  22. ;------------------------------------------------------------------------------*/
  23. ;
  24. ; OPTIMIZE: to do:
  25. ; - put read2_bits where possible (!d2 is affected)
  26. ; - ? move.l d0,(a4) .. move.l d0,4*2*SBLIMIT(a4) .. addq.l #4,a4
  27. ;     -> move.l d0,(a4)+ .. move.l d0,(4*2*SBLIMIT)-4(a4)
  28. ; - reduce some arrays from LONG to BYTE (bit_alloc, alloc, ...)
  29. ;
  30.           IFND       INCLUDE_SOURCE
  31.           incdir   "include:"
  32.           include  "exec/funcdef.i"
  33.           include  "exec/exec.i"
  34.           include  "exec/exec_lib.i"
  35.           ENDC
  36.           include  "mpega_decode_asm.i"
  37.           include  "mpega_decode_asm_tables.i"
  38.           include  "BitStream.i"
  39.           include  "AudioPort.i"
  40.  
  41.  
  42. SKIP_UPPER_BAND   equ    1     ; if skip upper part of sub band (half & quart freq)
  43.                   ; this flag is used for read & deqnor
  44.                   ; !!! incompatible with FILTER_?_SUM because
  45.                   ; if set filter use all of the sub band even in
  46.                   ; half or quart frequency mode
  47.  
  48. READ3_BITS      equ    1     ; if @BSTR_read3_bits func used
  49.  
  50.  
  51.  
  52.           XREF       @BSTR_open
  53.           XREF       @BSTR_close
  54.           XREF       @BSTR_rewind
  55.           XREF       @BSTR_end
  56.           XREF       @BSTR_read_bits
  57.           XREF       @BSTR_skip_bits
  58.           XREF       @BSTR_read3_bits
  59.           XREF       @BSTR_read2_bits
  60.           XREF       @BSTR_seek_sync
  61.           XREF       @BSTR_seek_tell
  62.  
  63.           XREF       @AU_open
  64.           XREF       @AU_write
  65.           XREF       @AU_close
  66.  
  67.           XDEF       @ASM_init_decode
  68.           XDEF       @ASM_read_header
  69.           XDEF       @ASM_decode_header
  70.  
  71.           XDEF       @ASM_I_decode_bitalloc
  72.           XDEF       @ASM_I_decode_scale
  73.           XDEF       @ASM_I_buffer_sample
  74.           XDEF       @ASM_I_deqnorm
  75.  
  76.           XDEF       @ASM_II_decode_bitalloc
  77.           XDEF       @ASM_II_decode_scale
  78.           XDEF       @ASM_II_buffer_sample
  79.           XDEF       @ASM_II_deqnorm
  80.  
  81.           XDEF       @ASM_sub_band_synthesis
  82.  
  83.           XDEF       @ASM_I_decode_frame
  84.           XDEF       @ASM_II_decode_frame
  85.  
  86.  
  87.           section  ASMCODE,code
  88.  
  89. ;           d0: int sub_band_size
  90. ;           d1: int output_8bits
  91. ;           d2: int quality (0..2)
  92. ;           0 : 1/4 windowing
  93. ;           1 : 1/2 windowing
  94. ;           2 : full quality
  95. ;
  96. @ASM_init_decode
  97.            movem.l    d2-d4,-(sp)
  98.            move.w    d1,output_8bits
  99.            move.w    d0,sub_band_size
  100.            moveq.l    #1,d3           ; skip value for full freq output
  101.            clr.w    half_freq
  102.            clr.w    quar_freq
  103.            cmp.w    #SBLIMIT/2,d0
  104.            beq    init_decode_1
  105.            cmp.w    #SBLIMIT/4,d0
  106.            beq    init_decode_2
  107.            bra    init_decode_5
  108. init_decode_1  move.w    #-1,half_freq
  109.            moveq.l    #2,d3           ; skip value for half freq output
  110.            bra    init_decode_5
  111. init_decode_2  move.w    #-1,quar_freq
  112.            moveq.l    #4,d3           ; skip value for quarter freq output
  113. init_decode_5  move.w    d3,window_skip
  114.            moveq.l    #0,d3           ; start offset for windowing
  115.            moveq.l    #8-1,d4        ; #coeff (#-1)/2 used for windowing
  116.            move.w    d2,quality
  117.            cmp.b    #2,d2           ; best quality
  118.            beq.s    init_decode_6
  119.            move.w    #2*128,d3
  120.            moveq.l    #4-1,d4
  121.            cmp.b    #1,d2
  122.            beq.s    init_decode_6
  123.            move.w    #3*128,d3
  124.            moveq.l    #2-1,d4
  125. init_decode_6  move.w    d3,window_start
  126.            move.w    d4,window_coeff
  127. init_decode_9  moveq.w    #64,d0
  128.            lea    band_offset,a0
  129.            move.w    d0,(a0)+
  130.            move.w    d0,(a0)+
  131.            lea    filter_buffer,a0
  132.            move.w    #2*2*HAN_SIZE-1,d0
  133. init_decode_91 clr.w    (a0)+
  134.            dbra    d0,init_decode_91
  135.            movem.l    (sp)+,d2-d4
  136.            rts
  137.  
  138. ;           Read header information
  139. ;
  140. ;           a0: frame_params *fr_ps
  141. ;           -> d0 = 0 if end of bitstream
  142. ;
  143. @ASM_read_header
  144.            movem.l    a2-a3/d2,-(sp)
  145.            move.l    a0,a3
  146.            move.l    fp_header(a3),a2     ; a2 = header
  147.            move.l    fp_bs(a3),a0         ; a0 = bitstream
  148.            moveq.l    #8,d1
  149.            move.b    #$FF,d2
  150. ASM_read_hdr1  bsr    @BSTR_read_bits
  151.            cmp.b    d0,d2
  152.            beq    ASM_read_hdr1      ; skip extra $FF sync
  153.            bfextu    d0{24:1},d1      ; Version
  154.            move.l    d1,hdr_version(a2)
  155.            bfextu    d0{25:2},d2      ; 4 - Layer
  156.            subq.l    #4,d2
  157.            neg.l    d2          ; Layer
  158.            move.l    d2,hdr_lay(a2)
  159.            bfextu    d0{27:1},d1      ; !Error protection
  160.            bchg    #0,d1
  161.            move.l    d1,hdr_error_protection(a2)
  162.            bfextu    d0{28:4},d1      ; Bit rate index
  163.            move.l    d1,hdr_bitrate_index(a2)
  164.  
  165.            subq.l    #1,d2
  166.            lsl.l    #4,d2             ; (lay-1)*16
  167.            add.l    d1,d2
  168.            lea    BITRATE_table,a1
  169.            move.w    (a1,d2.w*2),d1       ; d1 = bitrate
  170.            ext.l    d1
  171.            move.l    d1,fp_bitstream_rate(a3)
  172.  
  173.            moveq.l    #12,d1
  174.            bsr    @BSTR_read_bits   ; Read end of header
  175.            bfextu    d0{20:2},d1      ; Sampling frequency
  176.            move.l    d1,hdr_sampling_frequency(a2)
  177.  
  178.            lea    FREQ_table,a1
  179.            move.l    (a1,d1.w*4),d1
  180.            move.l    d1,fp_bitstream_freq(a3)
  181.  
  182.            bfextu    d0{22:1},d1      ; Padding
  183.            move.l    d1,hdr_padding(a2)
  184.            bfextu    d0{23:1},d1      ; Extension
  185.            move.l    d1,hdr_extension(a2)
  186.            bfextu    d0{24:2},d1      ; Mode
  187.            move.l    d1,hdr_mode(a2)
  188.            bfextu    d0{26:2},d1      ; Mode ext
  189.            move.l    d1,hdr_mode_ext(a2)
  190.            bfextu    d0{28:1},d1      ; Copyright
  191.            move.l    d1,hdr_copyright(a2)
  192.            bfextu    d0{29:1},d1      ; Original
  193.            move.l    d1,hdr_original(a2)
  194.            bfextu    d0{30:2},d1      ; Emphasis
  195.            move.l    d1,hdr_emphasis(a2)
  196.            bsr    @BSTR_end
  197.            not.l    d0
  198. ASM_read_hdr9  movem.l    (sp)+,a2-a3/d2
  199.            rts
  200.  
  201. ;           Get the right alloc table for layer II
  202. ;
  203. ;           a0: frame_params *fr_ps
  204. ;           -> d0.l = sub band limit
  205. ;           a0 is preserved
  206. ;
  207. ASM_II_get_alloc_table
  208.            movem.l    a2,-(sp)
  209.            move.l    fp_header(a0),a1     ; a1 = header
  210.            move.l    hdr_lay(a1),d0
  211.            subq.l    #1,d0
  212.            lsl.l    #4,d0             ; (lay-1)*16
  213.            move.l    hdr_bitrate_index(a1),d1
  214.            add.l    d1,d0
  215.            lea    BITRATE_table,a2
  216.            move.w    (a2,d0.w*2),d1       ; d1 = bitrate
  217.            move.l    fp_stereo(a0),d0
  218.            cmp.b    #1,d0
  219.            beq    ASM_II_get_a00
  220.            lsr.w    #1,d1             ; d1 = bitrate per channel
  221. ASM_II_get_a00 move.l    hdr_sampling_frequency(a1),d0
  222.            cmp.w    #56,d1
  223.            blt    ASM_II_get_a01
  224.            cmp.w    #1,d0             ; 48kHz
  225.            beq    ASM_II_get_a0
  226.            cmp.w    #80,d1
  227.            bgt    ASM_II_get_a01
  228. ASM_II_get_a0  moveq.l    #0,d0             ; -> alloc table 0
  229.            lea    ALLOC_table0,a1
  230.            bra    ASM_II_get_a4
  231. ASM_II_get_a01 cmp.w    #1,d0             ; 48kHz
  232.            beq    ASM_II_get_a02
  233.            cmp.w    #96,d1
  234.            blt    ASM_II_get_a02
  235. ASM_II_get_a1  moveq.l    #1,d0             ; -> alloc table 1
  236.            lea    ALLOC_table1,a1
  237.            bra    ASM_II_get_a4
  238. ASM_II_get_a02 cmp.w    #2,d0             ; 32kHz
  239.            beq    ASM_II_get_a3
  240.            cmp.w    #48,d1
  241.            bgt    ASM_II_get_a3
  242. ASM_II_get_a2  moveq.l    #2,d0             ; -> alloc table 2
  243.            lea    ALLOC_table2,a1
  244.            bra    ASM_II_get_a4
  245. ASM_II_get_a3  moveq.l    #3,d0             ; -> alloc table 3
  246.            lea    ALLOC_table3,a1
  247. ASM_II_get_a4  move.l    d0,fp_tab_num(a0)
  248.            move.l    a1,fp_alloc(a0)
  249.            lea    ALLOC_sub_band_limit,a1
  250.            move.l    (a1,d0.l*4),d0
  251. ;        move.l     d0,fp_sblimit(a0)
  252.            movem.l    (sp)+,a2
  253.            rts
  254.  
  255. ;           Get the joint sub band
  256. ;
  257. ;           a0: frame_params *fr_ps
  258. ;           -> d0.l = join sub band
  259. ;           a0 is preserved
  260. ;
  261. ASM_joint_sub_band
  262.            move.l    fp_header(a0),a1     ; a1 = header
  263.            move.l    hdr_lay(a1),d0
  264.            subq.l    #1,d0
  265.            lsl.l    #2,d0             ; (lay-1)*4
  266.            move.l    hdr_mode_ext(a1),d1
  267.            add.l    d1,d0
  268.            lea    JSB_table,a1
  269.            move.l    (a1,d0.l*4),d0
  270.            rts
  271.  
  272. ;           Decode header
  273. ;
  274. ;           a0: frame_params *fr_ps
  275. ;
  276. @ASM_decode_header
  277.            movem.l    a2,-(sp)
  278.            move.l    fp_header(a0),a2     ; a2 = header
  279.  
  280.            move.l    hdr_mode(a2),d1
  281.            move.l    d1,fp_actual_mode(a0)
  282.            moveq.l    #1,d0
  283.            cmp.w    #MPG_MD_MONO,d1
  284.            beq    ASM_decode_he1
  285.            addq.l    #1,d0
  286. ASM_decode_he1 move.l    d0,fp_stereo(a0)
  287.            move.l    d0,fp_channels(a0)
  288.            moveq.l    #SBLIMIT,d0
  289.            move.l    hdr_lay(a2),d1
  290.            cmp.w    #2,d1
  291.            bne    ASM_decode_he2
  292.            bsr    ASM_II_get_alloc_table
  293. ASM_decode_he2 move.l    d0,fp_sblimit(a0)
  294.            move.l    hdr_mode(a2),d1
  295.            cmp.w    #MPG_MD_JOINT_STEREO,d1
  296.            bne    ASM_decode_he3
  297.            bsr    ASM_joint_sub_band
  298. ASM_decode_he3 move.l    d0,fp_jsbound(a0)
  299.            movem.l    (sp)+,a2
  300.            rts
  301.  
  302. ;           Decode bit allocation (MPEG I Lay I)
  303. ;
  304. ;           a0: frame_params *fr_ps
  305.  
  306. @ASM_I_decode_bitalloc
  307.            movem.l    d2-d3/a2-a5,-(sp)
  308.  
  309.            move.l    a0,a2             ; a2 = frame_params
  310.            move.l    fp_bs(a2),a0         ; a0 = bitstream
  311.            move.l    fp_bit_alloc(a2),a4  ; a4 = &bitalloc[0][0]
  312.  
  313.            moveq.l    #4,d1          ; 4 bits per bitalloc
  314.            cmp.l    #1,fp_stereo(a2)
  315.            bgt.s    I_dec_bitall5
  316.  
  317.            moveq.l    #SBLIMIT-1,d2
  318. I_dec_bitall1
  319.            bsr    @BSTR_read_bits   ; read d1 bits from bitstream
  320.            move.l    d0,(a4)+
  321.            dbra    d2,I_dec_bitall1
  322.            bra.s    I_dec_bitall9
  323.  
  324. I_dec_bitall5
  325.            lea.l    4*SBLIMIT(a4),a5  ; a5 = &bit_alloc[1][0]
  326.            move.l    fp_jsbound(a2),d2
  327.            subq.l    #1,d2
  328.            bmi.s    I_dec_bitall7      ; jsbound <= 0 ?
  329. I_dec_bitall6
  330.            bsr    @BSTR_read_bits   ; read d1 bits from bitstream
  331.            move.l    d0,(a4)+
  332.            bsr    @BSTR_read_bits   ; read d1 bits from bitstream
  333.            move.l    d0,(a5)+
  334.            dbra    d2,I_dec_bitall6
  335. I_dec_bitall7
  336.            moveq.l    #SBLIMIT,d2
  337.            sub.l    fp_jsbound(a2),d2
  338.            subq.l    #1,d2
  339.            bmi.s    I_dec_bitall9      ; jsbound >= SBLIMIT
  340. I_dec_bitall8
  341.            bsr    @BSTR_read_bits   ; read d1 bits from bitstream
  342.            move.l    d0,(a4)+
  343.            move.l    d0,(a5)+          ; same band for 2 channels
  344.            dbra    d2,I_dec_bitall8
  345. I_dec_bitall9
  346.            movem.l    (sp)+,d2-d3/a2-a5
  347.            rts
  348.  
  349. ;           Decode scale (MPEG I Lay I)
  350. ;
  351. ;           a0: frame_params *fr_ps
  352. ;
  353. ;  OPTIMIZATION: bitalloc, scale_index -> BYTE
  354. ;
  355. @ASM_I_decode_scale
  356.            movem.l    d2-d7/a2-a6,-(sp)
  357.  
  358.            move.l    a0,a2             ; a2 = frame_params
  359.            move.l    fp_bs(a2),a0         ; a0 = bitstream
  360.            move.l    fp_scale_index(a2),a3
  361.            move.l    fp_bit_alloc(a2),a4  ; a4 = &bitalloc[0][0]
  362.  
  363.            moveq.l    #6,d1             ; 6 bits per scale_index
  364.            moveq.l    #SBLIMIT-1,d7
  365.  
  366.            cmp.l    #1,fp_stereo(a2)
  367.            bgt    I_dec_scale5     ; stereo
  368.  
  369. I_dec_scale1   moveq.l    #SCALE_RANGE-1,d0
  370.            tst.l    (a4)+
  371.            beq.s    I_dec_scale11
  372.            bsr    @BSTR_read_bits   ; read d1 bits from bitstream
  373. I_dec_scale11  move.l    d0,(a3)+
  374.            dbra    d7,I_dec_scale1
  375.            bra.s    I_dec_scale9
  376.  
  377. I_dec_scale5   lea    4*SBLIMIT(a4),a5
  378. I_dec_scale51  moveq.l    #SCALE_RANGE-1,d0
  379.            tst.l    (a4)+
  380.            beq.s    I_dec_scale52
  381.            bsr    @BSTR_read_bits   ; read d1 bits from bitstream
  382. I_dec_scale52  move.l    d0,(a3)
  383.            moveq.l    #SCALE_RANGE-1,d0
  384.            tst.l    (a5)+
  385.            beq.s    I_dec_scale53
  386.            bsr    @BSTR_read_bits   ; read d1 bits from bitstream
  387. I_dec_scale53  move.l    d0,4*3*SBLIMIT(a3)
  388.            addq.l    #4,a3
  389.            dbra    d7,I_dec_scale51
  390.  
  391. I_dec_scale9   movem.l    (sp)+,d2-d7/a2-a6
  392.            rts
  393.  
  394.  
  395.  
  396. ;           Decode bit allocation (MPEG I Lay II)
  397. ;
  398. ;           a0: frame_params *fr_ps
  399.  
  400. @ASM_II_decode_bitalloc
  401.            movem.l    d2-d3/a2-a5,-(sp)
  402.  
  403.            move.l    a0,a2             ; a2 = frame_params
  404.            move.l    fp_bs(a2),a0         ; a0 = bitstream
  405.            move.l    fp_bit_alloc(a2),a1  ; a1 = &bitalloc[0][0]
  406.            move.l    fp_alloc(a2),a3      ; a3 = &alloc[0][0]
  407.            move.l    a1,a4             ; a4 = &bitalloc[0][0]
  408.            moveq.l    #4*16,d3         ; d3 = next alloc step
  409.            cmp.l    #1,fp_stereo(a2)
  410.            bgt.s    II_dec_bitall5
  411.  
  412.            move.l    fp_sblimit(a2),d2
  413.            subq.l    #1,d2
  414.            bmi.s    II_dec_bitall2      ; sblimit <= 0 ?
  415. II_dec_bitall1
  416.            bfextu    (a3){ALLOC_O_BITS:ALLOC_W_BITS},d1    ; d1 = bits
  417.            bsr    @BSTR_read_bits   ; read d1 bits from bitstream
  418.            move.l    d0,(a4)+
  419.            add.l    d3,a3          ; next -> &alloc[i++][0]
  420.            dbra    d2,II_dec_bitall1
  421.            bra.s    II_dec_bitall9
  422. II_dec_bitall2
  423. ;        moveq.l  #SBLIMIT,d2
  424.            move.w    sub_band_size,d2
  425.            ext.l    d2
  426.            sub.l    fp_sblimit(a2),d2
  427.            subq.l    #1,d2
  428.            bmi.s    II_dec_bitall9      ; sblimit >= sub_band_size
  429.            clr.l    d0          ; 0 -> upper band
  430. II_dec_bitall3
  431.            move.l    d0,(a4)+
  432.            dbra    d2,II_dec_bitall3
  433.            bra.s    II_dec_bitall9
  434.  
  435. II_dec_bitall5
  436.            move.l    a4,a5
  437.            add.l    #4*SBLIMIT,a5      ; a5 = &bit_alloc[1][0]
  438.            move.l    fp_jsbound(a2),d2
  439.            subq.l    #1,d2
  440.            bmi.s    II_dec_bitall8      ; jsbound <= 0 ?
  441. II_dec_bitall6
  442.            bfextu    (a3){ALLOC_O_BITS:ALLOC_W_BITS},d1    ; d1 = bits
  443.            bsr    @BSTR_read_bits   ; read d1 bits from bitstream
  444.            move.l    d0,(a4)+
  445.            bsr    @BSTR_read_bits   ; read d1 bits from bitstream
  446.            move.l    d0,(a5)+
  447.            add.l    d3,a3          ; next -> &alloc[i++][0]
  448.            dbra    d2,II_dec_bitall6
  449.  
  450.            move.l    fp_sblimit(a2),d2
  451.            sub.l    fp_jsbound(a2),d2
  452.            subq.l    #1,d2
  453.            bmi.s    II_dec_bitall8      ; jsbound >= sblimit
  454. II_dec_bitall7
  455.            bfextu    (a3){ALLOC_O_BITS:ALLOC_W_BITS},d1    ; d1 = bits
  456.            bsr    @BSTR_read_bits   ; read d1 bits from bitstream
  457.            move.l    d0,(a4)+
  458.            move.l    d0,(a5)+          ; same band for 2 channels
  459.            add.l    d3,a3          ; next -> &alloc[i++][0]
  460.            dbra    d2,II_dec_bitall7
  461. II_dec_bitall8
  462. ;        moveq.l  #SBLIMIT,d2
  463.            move.w    sub_band_size,d2
  464.            ext.l    d2
  465.            sub.l    fp_sblimit(a2),d2
  466.            subq.l    #1,d2
  467.            bmi.s    II_dec_bitall9      ; sblimit >= sub_band_size
  468.            clr.l    d0          ; 0 -> upper band
  469. II_dec_bitall81
  470.            move.l    d0,(a4)+
  471.            move.l    d0,(a5)+
  472.            dbra    d2,II_dec_bitall81
  473. II_dec_bitall9
  474.            movem.l    (sp)+,d2-d3/a2-a5
  475.            rts
  476.  
  477. ;           Decode scale (MPEG I Lay II)
  478. ;
  479. ;           a0: frame_params *fr_ps
  480. ;
  481. ;  OPTIMIZATION: bitalloc, scfsi, scale_index -> BYTE
  482. ;
  483. @ASM_II_decode_scale
  484.            movem.l    d2-d7/a2-a6,-(sp)
  485.  
  486.            move.l    a0,a2             ; a2 = frame_params
  487.            move.l    fp_bs(a2),a0         ; a0 = bistream
  488.            move.l    fp_bit_alloc(a2),a1
  489.            move.l    fp_scfsi(a2),a3
  490.            move.l    fp_scale_index(a2),a4
  491.  
  492.            move.l    a1,a5          ; a5 = &bitalloc[0][0]
  493.            moveq.l    #2,d1          ; 2 bits per scfsi
  494.  
  495.            cmp.l    #1,fp_stereo(a2)
  496.            bgt    II_dec_scale5      ; stereo
  497.  
  498.            move.l    fp_sblimit(a2),d7
  499.            subq.l    #1,d7
  500.            bmi    II_dec_scale3      ; sblimit <= 0 !
  501.  
  502.            movem.l    a3/a5,-(sp)
  503. II_dec_scale1  tst.l    (a5)+
  504.            beq.s    II_dec_scale11
  505.            bsr    @BSTR_read_bits   ; read d1 bits from bitstream
  506.            move.l    d0,(a3)
  507. II_dec_scale11 addq.l    #4,a3
  508.            dbra    d7,II_dec_scale1
  509.            movem.l    (sp)+,a3/a5
  510. II_dec_scale2
  511.            move.l    fp_sblimit(a2),d7
  512.            subq.l    #1,d7
  513.            moveq.l    #6,d1
  514. II_dec_scale21 tst.l    (a5)+
  515.            beq.s    II_dec_scale26
  516.            move.l    (a3)+,d0
  517.            bne.s    II_dec_scale22         ; scfsi[0][i] > 0
  518.            bsr    @BSTR_read3_bits     ; read 3*d1 bits from bitstream
  519.            move.l    d4,(a4)              ; scale_index[0][0][i]
  520.            move.l    d5,4*SBLIMIT(a4)     ; scale_index[0][1][i]
  521.            move.l    d6,8*SBLIMIT(a4)     ; scale_index[0][2][i]
  522.            bra.s    II_dec_scale27
  523. II_dec_scale22 subq.b    #1,d0
  524.            bne.s    II_dec_scale23         ; scfsi[0][i] > 1
  525.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  526.            move.l    d0,(a4)              ; scale_index[0][0][i]
  527.            move.l    d0,4*SBLIMIT(a4)     ; = scale_index[0][1][i]
  528.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  529.            move.l    d0,8*SBLIMIT(a4)     ; scale_index[0][2][i]
  530.            bra.s    II_dec_scale27
  531. II_dec_scale23 subq.b    #1,d0
  532.            bne.s    II_dec_scale24         ; scfsi[0][i] > 2
  533.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  534.            move.l    d0,(a4)              ; scale_index[0][0][i]
  535.            move.l    d0,4*SBLIMIT(a4)     ; = scale_index[0][1][i]
  536.            move.l    d0,8*SBLIMIT(a4)     ; = scale_index[0][2][i]
  537.            bra.s    II_dec_scale27
  538. II_dec_scale24                     ; scfsi[0][i] == 3
  539.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  540.            move.l    d0,(a4)              ; scale_index[0][0][i]
  541.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  542.            move.l    d0,4*SBLIMIT(a4)     ; scale_index[0][1][i]
  543.            move.l    d0,8*SBLIMIT(a4)     ; = scale_index[0][2][i]
  544.            bra.s    II_dec_scale27
  545. II_dec_scale26
  546.            moveq.l    #SCALE_RANGE-1,d0
  547.            move.l    d0,(a4)              ; scale_index[0][0][i]
  548.            move.l    d0,4*SBLIMIT(a4)     ; = scale_index[0][1][i]
  549.            move.l    d0,8*SBLIMIT(a4)     ; = scale_index[0][2][i]
  550.            addq.l    #4,a3             ; next scfsi
  551. II_dec_scale27
  552.            addq.l    #4,a4             ; next scale_index
  553.            dbra    d7,II_dec_scale21
  554.  
  555. II_dec_scale3
  556. ;        moveq.l  #SBLIMIT,d7
  557.            move.w    sub_band_size,d7
  558.            ext.l    d7
  559.            sub.l    fp_sblimit(a2),d7
  560.            subq.l    #1,d7
  561.            bmi    II_dec_scale9        ; sblimit >= sub_band_size
  562.            moveq.l    #SCALE_RANGE-1,d0
  563. II_dec_scale31 move.l    d0,(a4)              ; scale_index[0][0][i]
  564.            move.l    d0,4*SBLIMIT(a4)     ; = scale_index[0][1][i]
  565.            move.l    d0,8*SBLIMIT(a4)     ; = scale_index[0][2][i]
  566.            addq.l    #4,a4             ; next scale_index
  567.            dbra    d7,II_dec_scale31
  568.            bra    II_dec_scale9
  569.  
  570. II_dec_scale5
  571.            move.l    fp_sblimit(a2),d7
  572.            subq.l    #1,d7
  573.            bmi    II_dec_scale8        ; sblimit <= 0 !
  574.  
  575.            movem.l    a3/a5,-(sp)
  576. II_dec_scale51 tst.l    (a5)
  577.            beq.s    II_dec_scale52
  578.            bsr    @BSTR_read_bits   ; read d1 bits from bitstream
  579.            move.l    d0,(a3)
  580. II_dec_scale52 tst.l    4*SBLIMIT(a5)
  581.            beq.s    II_dec_scale53
  582.            bsr    @BSTR_read_bits   ; read d1 bits from bitstream
  583.            move.l    d0,4*SBLIMIT(a3)
  584. II_dec_scale53 addq.l    #4,a3
  585.            addq.l    #4,a5
  586.            dbra    d7,II_dec_scale51
  587.            movem.l    (sp)+,a3/a5
  588.  
  589.            move.l    fp_sblimit(a2),d7
  590.            subq.l    #1,d7
  591.            moveq.l    #6,d1
  592. II_dec_scale61 tst.l    (a5)
  593.            beq.s    II_dec_scale66
  594.            move.l    (a3),d0
  595.            bne.s    II_dec_scale62         ; scfsi[0][i] > 0
  596.            bsr    @BSTR_read3_bits     ; read 3*d1 bits from bitstream
  597.            move.l    d4,(a4)              ; scale_index[0][0][i]
  598.            move.l    d5,4*SBLIMIT(a4)     ; scale_index[0][1][i]
  599.            move.l    d6,8*SBLIMIT(a4)     ; scale_index[0][2][i]
  600.            bra.s    II_dec_scale67
  601. II_dec_scale62 subq.b    #1,d0
  602.            bne.s    II_dec_scale63         ; scfsi[0][i] > 1
  603.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  604.            move.l    d0,(a4)              ; scale_index[0][0][i]
  605.            move.l    d0,4*SBLIMIT(a4)     ; = scale_index[0][1][i]
  606.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  607.            move.l    d0,8*SBLIMIT(a4)     ; scale_index[0][2][i]
  608.            bra.s    II_dec_scale67
  609. II_dec_scale63 subq.b    #1,d0
  610.            bne.s    II_dec_scale64         ; scfsi[0][i] > 2
  611.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  612.            move.l    d0,(a4)              ; scale_index[0][0][i]
  613.            move.l    d0,4*SBLIMIT(a4)     ; = scale_index[0][1][i]
  614.            move.l    d0,8*SBLIMIT(a4)     ; = scale_index[0][2][i]
  615.            bra.s    II_dec_scale67
  616. II_dec_scale64
  617.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  618.            move.l    d0,(a4)              ; scale_index[0][0][i]
  619.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  620.            move.l    d0,4*SBLIMIT(a4)     ; scale_index[0][1][i]
  621.            move.l    d0,8*SBLIMIT(a4)     ; = scale_index[0][2][i]
  622.            bra.s    II_dec_scale67
  623. II_dec_scale66
  624.            moveq.l    #SCALE_RANGE-1,d0
  625.            move.l    d0,(a4)              ; scale_index[0][0][i]
  626.            move.l    d0,4*SBLIMIT(a4)     ; = scale_index[0][1][i]
  627.            move.l    d0,8*SBLIMIT(a4)     ; = scale_index[0][2][i]
  628. II_dec_scale67
  629.            tst.l    4*SBLIMIT(a5)
  630.            beq.s    II_dec_scale76
  631.            move.l    4*SBLIMIT(a3),d0
  632.            bne.s    II_dec_scale72         ; scfsi[0][i] > 0
  633.            bsr    @BSTR_read3_bits     ; read 3*d1 bits from bitstream
  634.            move.l    d4,4*3*SBLIMIT(a4)   ; scale_index[1][0][i]
  635.            move.l    d5,4*4*SBLIMIT(a4)   ; scale_index[1][1][i]
  636.            move.l    d6,4*5*SBLIMIT(a4)   ; scale_index[1][2][i]
  637.            bra.s    II_dec_scale77
  638. II_dec_scale72 subq.b    #1,d0
  639.            bne.s    II_dec_scale73         ; scfsi[0][i] > 1
  640.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  641.            move.l    d0,4*3*SBLIMIT(a4)   ; scale_index[1][0][i]
  642.            move.l    d0,4*4*SBLIMIT(a4)   ; = scale_index[1][1][i]
  643.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  644.            move.l    d0,4*5*SBLIMIT(a4)   ; scale_index[1][2][i]
  645.            bra.s    II_dec_scale77
  646. II_dec_scale73 subq.b    #1,d0
  647.            bne.s    II_dec_scale74         ; scfsi[0][i] > 2
  648.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  649.            move.l    d0,4*3*SBLIMIT(a4)   ; scale_index[1][0][i]
  650.            move.l    d0,4*4*SBLIMIT(a4)   ; = scale_index[1][1][i]
  651.            move.l    d0,4*5*SBLIMIT(a4)   ; = scale_index[1][2][i]
  652.            bra.s    II_dec_scale77
  653. II_dec_scale74
  654.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  655.            move.l    d0,4*3*SBLIMIT(a4)   ; scale_index[1][0][i]
  656.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  657.            move.l    d0,4*4*SBLIMIT(a4)   ; = scale_index[1][1][i]
  658.            move.l    d0,4*5*SBLIMIT(a4)   ; = scale_index[1][2][i]
  659.            bra.s    II_dec_scale77
  660. II_dec_scale76
  661.            moveq.l    #SCALE_RANGE-1,d0
  662.            move.l    d0,4*3*SBLIMIT(a4)   ; scale_index[1][0][i]
  663.            move.l    d0,4*4*SBLIMIT(a4)   ; = scale_index[1][1][i]
  664.            move.l    d0,4*5*SBLIMIT(a4)   ; = scale_index[1][2][i]
  665. II_dec_scale77
  666.            addq.l    #4,a3             ; next scfsi
  667.            addq.l    #4,a4             ; next scale_index
  668.            addq.l    #4,a5             ; next bitalloc
  669.            dbra    d7,II_dec_scale61
  670.  
  671. II_dec_scale8
  672. ;           moveq.l    #SBLIMIT,d7
  673.            move.w    sub_band_size,d7
  674.            ext.l    d7
  675.            sub.l    fp_sblimit(a2),d7
  676.            subq.l    #1,d7
  677.            bmi    II_dec_scale9        ; sblimit >= sub_band_size
  678.            moveq.l    #SCALE_RANGE-1,d0
  679. II_dec_scale81 move.l    d0,(a4)              ; scale_index[0][0][i]
  680.            move.l    d0,4*SBLIMIT(a4)     ; = scale_index[0][1][i]
  681.            move.l    d0,8*SBLIMIT(a4)     ; = scale_index[0][2][i]
  682.            move.l    d0,4*3*SBLIMIT(a4)   ; scale_index[1][0][i]
  683.            move.l    d0,4*4*SBLIMIT(a4)   ; = scale_index[1][1][i]
  684.            move.l    d0,4*5*SBLIMIT(a4)   ; = scale_index[1][2][i]
  685.            addq.l    #4,a4             ; next scale_index
  686.            dbra    d7,II_dec_scale81
  687. ;        bra     II_dec_scale9
  688.  
  689. II_dec_scale9  movem.l    (sp)+,d2-d7/a2-a6
  690.            rts
  691.  
  692.  
  693. ;           Read a sub band sample (MPEG I Lay I) into a buffer
  694. ;
  695. ;           a0: frame_params *fr_ps
  696. ;
  697.  
  698. @ASM_I_buffer_sample
  699.            movem.l    d2-d7/a0-a6,-(sp)
  700.  
  701.            move.l    fp_sblimit(a0),d0
  702.            move.l    fp_channels(a0),d1
  703.            move.l    fp_jsbound(a0),d2
  704.            move.l    fp_alloc(a0),a3
  705.            move.l    fp_bit_alloc(a0),a2
  706.            move.l    fp_sample(a0),a1
  707.            move.l    fp_bs(a0),a0
  708.  
  709.            move.w    d0,bsamp_sblimit
  710.            move.w    d1,bsamp_channels
  711.            move.w    d2,bsamp_jsbound
  712.            move.l    a1,a4             ; a4 = &sample[0][0][0]
  713.  
  714.            clr.l    d7             ; d7=i:0..sblimit
  715. ASM_I_bsamp_1
  716.            move.l    (0,a2,d7.w*4),d1     ; d1 = bit_alloc[0][d7]
  717.            beq    ASM_I_bsamp_3         ; no bit allocated for this sample
  718.  
  719.            addq.l    #1,d1             ; d1 = bits to read
  720.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  721.            move.l    d0,(a4)              ; sample[0][0][i]
  722.            bra.s    ASM_I_bsamp_4
  723. ASM_I_bsamp_3
  724.            clr.l    (a4)                 ; sample[0][0][i] = 0
  725. ASM_I_bsamp_4
  726.            cmp.w    #1,bsamp_channels
  727.            beq    ASM_I_bsamp_8        ; only 1 channel
  728.            cmp.w    bsamp_jsbound,d7
  729.            bge    ASM_I_bsamp_7        ; i>=jsbound & stereo -> L=R
  730.  
  731.            move.l    (4*SBLIMIT,a2,d7.w*4),d1     ; d1 = bit_alloc[1][d7]
  732.            beq    ASM_I_bsamp_6        ; no bit allocated for this sample
  733.  
  734.            addq.l    #1,d1             ; d1 = bits to read
  735.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  736.            move.l    d0,4*3*SBLIMIT(a4)   ; sample[1][0][i]
  737.            bra    ASM_I_bsamp_8
  738. ASM_I_bsamp_6
  739.            clr.l    4*3*SBLIMIT(a4)      ; sample[1][0][i] = 0
  740.            bra    ASM_I_bsamp_8
  741. ASM_I_bsamp_7
  742.            move.l    (a4),4*3*SBLIMIT(a4)          ; sample[1][0][i] = sample[0][0][i]
  743. ASM_I_bsamp_8
  744.            addq.l    #4,a4             ; next sample ptr
  745.            addq.w    #1,d7             ; i++
  746.            IFND    SKIP_UPPER_BAND
  747.            cmp.w    bsamp_sblimit,d7
  748.            blt    ASM_I_bsamp_1        ; i<sblimit
  749.            ELSE
  750.            cmp.w    sub_band_size,d7
  751.            bge.s    ASM_I_bsamp_81        ; i >= sub_band_size -> skip others
  752.            cmp.w    bsamp_sblimit,d7
  753.            blt    ASM_I_bsamp_1
  754.            bra    ASM_I_bsamp_9
  755. ASM_I_bsamp_81
  756.            cmp.w    bsamp_sblimit,d7
  757.            bge    ASM_I_bsamp_9        ; i >= sblimit -> end of read
  758.  
  759.            move.l    (0,a2,d7.w*4),d1    ; d1 = bit_alloc[0][d7]
  760.            beq    ASM_I_bsamp_84        ; no bit allocated for this sample
  761.  
  762.            addq.l    #1,d1             ; d1 = bits to read
  763.            bsr    @BSTR_skip_bits      ; skip d1 bits from bitstream
  764. ASM_I_bsamp_84
  765.            cmp.w    #1,bsamp_channels
  766.            beq    ASM_I_bsamp_88        ; only 1 channel
  767.            cmp.w    bsamp_jsbound,d7
  768.            bge    ASM_I_bsamp_88        ; i>=jsbound & stereo -> L=R
  769.  
  770.            move.l    (4*SBLIMIT,a2,d7.w*4),d1   ; d1 = bit_alloc[1][d7]
  771.            beq.s     ASM_I_bsamp_88      ; no bit allocated for this sample
  772.  
  773.            addq.l    #1,d1             ; d1 = bits to read
  774.            bsr    @BSTR_skip_bits      ; skip d1 bits from bitstream
  775. ASM_I_bsamp_88
  776.            addq.l    #4,a4             ; next sample ptr
  777.            addq.w    #1,d7             ; i++
  778.            bra    ASM_I_bsamp_81
  779.            ENDC
  780. ASM_I_bsamp_9
  781.            IFND    SKIP_UPPER_BAND
  782.            cmp.w    #SBLIMIT,d7
  783.            ELSE
  784.            cmp.w    sub_band_size,d7
  785.            ENDC
  786.            bge    ASM_I_bsamp_end
  787.  
  788.            addq.w    #1,d7
  789.            clr.l    (a4)                 ; sample[0][0][i] = 0
  790.            cmp.w    #1,bsamp_channels
  791.            beq    ASM_I_bsamp_91         ; only 1 channel
  792.            clr.l    4*3*SBLIMIT(a4)      ; sample[1][0][i] = 0
  793. ASM_I_bsamp_91
  794.            addq.l    #4,a4             ; next sample ptr
  795.            bra    ASM_I_bsamp_9
  796. ASM_I_bsamp_end
  797.            movem.l    (sp)+,d2-d7/a0-a6
  798.            rts
  799.  
  800.  
  801.  
  802.  
  803. ;           Read a sub band sample (MPEG I Lay II) into a buffer
  804. ;
  805. ;           a0: frame_params *fr_ps
  806. ;
  807.  
  808. @ASM_II_buffer_sample
  809.            movem.l    d2-d7/a0-a6,-(sp)
  810.  
  811.            move.l    fp_sblimit(a0),d0
  812.            move.l    fp_channels(a0),d1
  813.            move.l    fp_jsbound(a0),d2
  814.            move.l    fp_alloc(a0),a3
  815.            move.l    fp_bit_alloc(a0),a2
  816.            move.l    fp_sample(a0),a1
  817.            move.l    fp_bs(a0),a0
  818.  
  819.            move.w    d0,bsamp_sblimit
  820.            move.w    d1,bsamp_channels
  821.            move.w    d2,bsamp_jsbound
  822.            move.l    a1,a4             ; a4 = &sample[0][0][0]
  823.  
  824.            clr.l    d7             ; d7=i:0..sblimit
  825. ASM_II_bsamp_1
  826.            move.l    (0,a2,d7.w*4),d3     ; d3 = bit_alloc[0][d7]
  827.            beq    ASM_II_bsamp_3         ; no bit allocated for this sample
  828.            move.l    (a3,d3.w*4),d3       ; d3 = alloc_table[i][d3]
  829.            bfextu    d3{ALLOC_O_BITS:ALLOC_W_BITS},d1    ; d1 = bits
  830.            btst    #ALLOC_B_GROUP,d3
  831.            beq    ASM_II_bsamp_2         ; group <> 3
  832.            ; read each sub band sample separately
  833.            IFND    READ3_BITS
  834.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  835.            move.l    d0,(a4)              ; sample[0][0][i]
  836.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  837.            move.l    d0,4*SBLIMIT(a4)     ; sample[0][1][i]
  838.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  839.            move.l    d0,8*SBLIMIT(a4)     ; sample[0][2][i]
  840.            ELSE
  841.            bsr    @BSTR_read3_bits     ; read 3*d1 bits from bitstream
  842.            move.l    d4,(a4)              ; sample[0][0][i]
  843.            move.l    d5,4*SBLIMIT(a4)     ; sample[0][1][i]
  844.            move.l    d6,8*SBLIMIT(a4)     ; sample[0][2][i]
  845.            ENDC
  846.            bra    ASM_II_bsamp_4
  847. ASM_II_bsamp_2                     ; bit_alloc.steps = 3, 5, 9
  848.            bfextu    d3{ALLOC_O_STEPS:ALLOC_W_STEPS},d4  ; d4 = steps
  849.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  850.            move.w    d0,d1
  851.            divs.w    d4,d1             ; d1/d4 -> d1.h=r d1.l=q
  852.            move.l    d1,d0
  853.            swap    d0
  854.            ext.l    d0
  855.            move.l    d0,(a4)              ; r -> sample[0][0][i]
  856.            ext.l    d1
  857.            divs.w    d4,d1
  858.            move.l    d1,d0
  859.            swap    d0
  860.            ext.l    d0
  861.            move.l    d0,4*SBLIMIT(a4)     ; r -> sample[0][1][i]
  862.            ext.l    d1
  863.            move.l    d1,8*SBLIMIT(a4)     ; q -> sample[0][2][i]
  864.            bra    ASM_II_bsamp_4
  865. ASM_II_bsamp_3
  866.            clr.l    (a4)                 ; sample[0][0][i] = 0
  867.            clr.l    4*SBLIMIT(a4)        ; sample[0][1][i] = 0
  868.            clr.l    8*SBLIMIT(a4)        ; sample[0][2][i] = 0
  869. ASM_II_bsamp_4
  870.            cmp.w    #1,bsamp_channels
  871.            beq    ASM_II_bsamp_8         ; only 1 channel
  872.            cmp.w    bsamp_jsbound,d7
  873.            bge    ASM_II_bsamp_7         ; i>=jsbound & stereo -> L=R
  874.  
  875.            move.l    (4*SBLIMIT,a2,d7.w*4),d3     ; d3 = bit_alloc[1][d7]
  876.            beq    ASM_II_bsamp_6         ; no bit allocated for this sample
  877.            move.l    (a3,d3.w*4),d3       ; d3 = alloc_table[i][d3]
  878.            bfextu    d3{ALLOC_O_BITS:ALLOC_W_BITS},d1    ; d1 = bits
  879.            btst    #ALLOC_B_GROUP,d3
  880.            beq    ASM_II_bsamp_5         ; group <> 3
  881.            IFND    READ3_BITS
  882.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  883.            move.l    d0,4*3*SBLIMIT(a4)   ; sample[1][0][i]
  884.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  885.            move.l    d0,4*4*SBLIMIT(a4)   ; sample[1][1][i]
  886.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  887.            move.l    d0,4*5*SBLIMIT(a4)   ; sample[1][2][i]
  888.            ELSE
  889.            bsr    @BSTR_read3_bits     ; read 3*d1 bits from bitstream
  890.            move.l    d4,4*3*SBLIMIT(a4)   ; sample[1][0][i]
  891.            move.l    d5,4*4*SBLIMIT(a4)   ; sample[1][1][i]
  892.            move.l    d6,4*5*SBLIMIT(a4)   ; sample[1][2][i]
  893.            ENDC
  894.            bra    ASM_II_bsamp_8
  895. ASM_II_bsamp_5                     ; bit_alloc.steps = 3, 5, 9
  896.            bfextu    d3{ALLOC_O_STEPS:ALLOC_W_STEPS},d4  ; d4 = steps
  897.            bsr    @BSTR_read_bits      ; read d1 bits from bitstream
  898.            tst.w    d4
  899.            beq.s    ASM_II_bsamp_6         ; if d4=0 (should not happend !)
  900.            move.w    d0,d1
  901.            divs.w    d4,d1             ; d1/d4 -> d1.h=r d1.l=q
  902.            move.l    d1,d0
  903.            swap    d0
  904.            ext.l    d0
  905.            move.l    d0,4*3*SBLIMIT(a4)   ; r -> sample[1][0][i]
  906.            ext.l    d1
  907.            divs.w    d4,d1
  908.            move.l    d1,d0
  909.            swap    d0
  910.            ext.l    d0
  911.            move.l    d0,4*4*SBLIMIT(a4)   ; r -> sample[1][1][i]
  912.            ext.l    d1
  913.            move.l    d1,4*5*SBLIMIT(a4)   ; q -> sample[1][2][i]
  914.            bra    ASM_II_bsamp_8
  915. ASM_II_bsamp_6
  916.            clr.l    4*3*SBLIMIT(a4)      ; sample[1][0][i] = 0
  917.            clr.l    4*4*SBLIMIT(a4)      ; sample[1][1][i] = 0
  918.            clr.l    4*5*SBLIMIT(a4)      ; sample[1][2][i] = 0
  919.            bra    ASM_II_bsamp_8
  920. ASM_II_bsamp_7
  921.            move.l    (a4),4*3*SBLIMIT(a4)          ; sample[1][0][i] = sample[0][0][i]
  922.            move.l    4*SBLIMIT(a4),4*4*SBLIMIT(a4) ; sample[1][1][i] = sample[0][1][i]
  923.            move.l    8*SBLIMIT(a4),4*5*SBLIMIT(a4) ; sample[1][2][i] = sample[0][2][i]
  924. ASM_II_bsamp_8
  925.            addq.l    #4,a4             ; next sample ptr
  926.            add.l    #4*16,a3         ; next alloc_table ptr
  927.            addq.w    #1,d7             ; i++
  928.            IFND    SKIP_UPPER_BAND
  929.            cmp.w    bsamp_sblimit,d7
  930.            blt    ASM_II_bsamp_1         ; i<sblimit
  931.            ELSE
  932.            cmp.w    sub_band_size,d7
  933.            bge.s    ASM_II_bsamp_81      ; i >= sub_band_size -> skip others
  934.            cmp.w    bsamp_sblimit,d7
  935.            blt    ASM_II_bsamp_1
  936.            bra    ASM_II_bsamp_9
  937. ASM_II_bsamp_81
  938.            cmp.w    bsamp_sblimit,d7
  939.            bge    ASM_II_bsamp_9         ; i >= sblimit -> end of read
  940.  
  941.            move.l    (0,a2,d7.w*4),d3     ; d3 = bit_alloc[0][d7]
  942.            beq    ASM_II_bsamp_84      ; no bit allocated for this sample
  943.            move.l    (a3,d3.w*4),d3       ; d3 = alloc_table[i][d3]
  944.            bfextu    d3{ALLOC_O_BITS:ALLOC_W_BITS},d1    ; d1 = bits
  945.            btst    #ALLOC_B_GROUP,d3
  946.            beq    ASM_II_bsamp_82      ; group <> 3
  947.            ; read each sub band sample separately
  948.            move.l    d1,d2
  949.            add.l    d1,d1
  950.            add.l    d2,d1
  951.            bsr    @BSTR_skip_bits      ; skip 3*d1 bits from bitstream
  952.            bra    ASM_II_bsamp_84
  953. ASM_II_bsamp_82
  954.            bsr    @BSTR_skip_bits      ; skip d1 bits from bitstream
  955. ASM_II_bsamp_84
  956.            cmp.w    #1,bsamp_channels
  957.            beq    ASM_II_bsamp_88      ; only 1 channel
  958.            cmp.w    bsamp_jsbound,d7
  959.            bge    ASM_II_bsamp_88      ; i>=jsbound & stereo -> L=R
  960.  
  961.            move.l    (4*SBLIMIT,a2,d7.w*4),d3     ; d3 = bit_alloc[1][d7]
  962.            beq.s     ASM_II_bsamp_88      ; no bit allocated for this sample
  963.            move.l    (a3,d3.w*4),d3       ; d3 = alloc_table[i][d3]
  964.            bfextu    d3{ALLOC_O_BITS:ALLOC_W_BITS},d1    ; d1 = bits
  965.            btst    #ALLOC_B_GROUP,d3
  966.            beq    ASM_II_bsamp_85      ; group <> 3
  967.            ; read each sub band sample separately
  968.            move.l    d1,d2
  969.            add.l    d1,d1
  970.            add.l    d2,d1
  971.            bsr    @BSTR_skip_bits      ; skip 3*d1 bits from bitstream
  972.            bra    ASM_II_bsamp_88
  973. ASM_II_bsamp_85
  974.            bsr    @BSTR_skip_bits      ; skip d1 bits from bitstream
  975. ASM_II_bsamp_88
  976.            addq.l    #4,a4             ; next sample ptr
  977.            add.l    #4*16,a3         ; next alloc_table ptr
  978.            addq.w    #1,d7             ; i++
  979.            bra    ASM_II_bsamp_81
  980.            ENDC
  981. ASM_II_bsamp_9
  982.            IFND    SKIP_UPPER_BAND
  983.            cmp.w    #SBLIMIT,d7
  984.            ELSE
  985.            cmp.w    sub_band_size,d7
  986.            ENDC
  987.            bge    ASM_II_bsamp_end
  988.  
  989.            addq.w    #1,d7
  990.            clr.l    (a4)                 ; sample[0][0][i] = 0
  991.            clr.l    4*SBLIMIT(a4)        ; sample[0][1][i] = 0
  992.            clr.l    8*SBLIMIT(a4)        ; sample[0][2][i] = 0
  993.            cmp.w    #1,bsamp_channels
  994.            beq    ASM_II_bsamp_91      ; only 1 channel
  995.            clr.l    4*3*SBLIMIT(a4)      ; sample[1][0][i] = 0
  996.            clr.l    4*4*SBLIMIT(a4)      ; sample[1][1][i] = 0
  997.            clr.l    4*5*SBLIMIT(a4)      ; sample[1][2][i] = 0
  998. ASM_II_bsamp_91
  999.            addq.l    #4,a4
  1000.            bra    ASM_II_bsamp_9
  1001. ASM_II_bsamp_end
  1002.            movem.l    (sp)+,d2-d7/a0-a6
  1003.            rts
  1004.  
  1005. ;           Dequantize & denormalize samples (layer I)
  1006. ;
  1007. ;           a0:   frame_params *fr_ps
  1008.  
  1009. @ASM_I_deqnorm
  1010.            movem.l    d2-d7/a2-a6,-(sp)
  1011.  
  1012.            move.l    fp_sblimit(a0),d0
  1013.            move.l    fp_stereo(a0),d1
  1014.            move.l    fp_scale_index(a0),a3
  1015.            move.l    fp_fraction(a0),a2
  1016.            move.l    fp_bit_alloc(a0),a1
  1017.            move.l    fp_sample(a0),a0
  1018.  
  1019.            move.w    d0,sub_band_limit    ; sblimit
  1020.            IFD    SKIP_UPPER_BAND
  1021.            cmp.w    sub_band_size,d0
  1022.            ble.s    ASM_I_deqnorm_0      ; sub_band_limit <= sub_band_size
  1023.            move.w    sub_band_size,sub_band_limit
  1024. ASM_I_deqnorm_0
  1025.            ENDC
  1026.            move.w    d1,channels         ; stereo ?
  1027.            mulu.w    #SBLIMIT,d2         ; x*SBLIMIT
  1028.            moveq.l    #MULT_FACTOR,d7
  1029.            moveq.l    #DEQUANT_FACTOR,d6
  1030.            lea.l    mult_table,a5
  1031.  
  1032. ASM_I_deqnorm_1
  1033.            movem.l    d2/a0-a4,-(sp)
  1034.            move.l    a0,a6             ; a6 = sample[k][0][0]
  1035. ;        lea.l     (a3,d2.w*4),a3       ; a3 = &scale_index[k][x][0]
  1036.            move.w    sub_band_limit,d0
  1037.            move.w    d0,sub_band_index
  1038.  
  1039.            lea.l    dequantize_I_table,a0
  1040. ASM_I_deqnorm_2
  1041.            subq.w    #1,sub_band_index
  1042.            bmi    ASM_I_deqnorm_7
  1043.  
  1044.            move.l    (a3)+,d0             ; d0 = *scale++
  1045.            move.l    (a1)+,d1             ; d1 = *bit_alloc++;
  1046.            beq    ASM_I_deqnorm_5      ; no bit allocated
  1047.  
  1048.            move.w    (a5,d0.w*2),d5       ; m = d5;
  1049.            move.w    (a0,d1.w*4),d3       ; d
  1050.            move.w    (2,a0,d1.w*4),d4     ; c
  1051.            muls.w    d5,d4             ; c*m
  1052.            asr.l    d7,d4             ; >>MULT_FACTOR
  1053.  
  1054.            move.l    (a6)+,d0             ; sample[k][0][i]
  1055.            moveq.w    #31-16,d2
  1056.            sub.w    d1,d2
  1057.            asl.l    d2,d0             ; left justify sample (normalize)
  1058.            bchg    #15,d0             ; Invert Msb of sample
  1059.            asr.w    #15-INT_FACTOR,d0
  1060.            add.w    d3,d0             ; d0 + d
  1061.            muls.w    d4,d0             ; * c*m
  1062.            asr.l    d6,d0             ; >>DEQUANT_FACTOR
  1063.            move.w    d0,(a2)+             ; -> fraction[k][0][i]
  1064.  
  1065.            bra    ASM_I_deqnorm_2     ; next sub_band
  1066. ASM_I_deqnorm_5
  1067.            addq.l    #4,a6             ; -> sample ptr ++ (skipped)
  1068.            clr.w    (a2)+                ; fraction[k][0][i] = 0
  1069. ASM_I_deqnorm_6
  1070.            bra    ASM_I_deqnorm_2     ; next sub_band
  1071.  
  1072. ASM_I_deqnorm_7
  1073.            move.w    sub_band_limit,d0
  1074. ASM_I_deqnorm_8
  1075.            IFND    SKIP_UPPER_BAND      ; 27/05/1995
  1076.            cmp.w    #SBLIMIT,d0
  1077.            ELSE                 ; !!! incompatible with FILTER_?_SUM
  1078.            cmp.w    sub_band_size,d0
  1079.            ENDC
  1080.            bge    ASM_I_deqnorm_9
  1081.            clr.w    (a2)+                ; fraction[k][0][i] = 0
  1082.            addq.w    #1,d0
  1083.            bra    ASM_I_deqnorm_8
  1084. ASM_I_deqnorm_9
  1085.            movem.l    (sp)+,d2/a0-a4
  1086.            subq.w    #1,channels
  1087.            ble    ASM_I_deqnorm_end
  1088.            add.l    #4*3*SBLIMIT,a0      ; next -> &sample[k][0][0]
  1089.            add.l    #4*SBLIMIT,a1         ; next -> &bit_alloc[k][0]
  1090.            add.l    #2*3*SBLIMIT,a2      ; next -> &fraction[k][0][0]
  1091.            add.l    #4*3*SBLIMIT,a3      ; next -> &scale_index[k][0][0]
  1092.            bra    ASM_I_deqnorm_1
  1093.  
  1094. ASM_I_deqnorm_end
  1095.            movem.l    (sp)+,d2-d7/a2-a6
  1096.            rts
  1097.  
  1098.  
  1099. ;           Dequantize & denormalize samples (layer II)
  1100. ;
  1101. ;           a0:   frame_params *fr_ps
  1102. ;           d0.l: int x      (0..2)
  1103.  
  1104. @ASM_II_deqnorm
  1105.            movem.l    d2-d7/a2-a6,-(sp)
  1106.  
  1107.            move.l    d0,d2
  1108.            move.l    fp_sblimit(a0),d0
  1109.            move.l    fp_stereo(a0),d1
  1110.            move.l    fp_alloc(a0),a4
  1111.            move.l    fp_scale_index(a0),a3
  1112.            move.l    fp_fraction(a0),a2
  1113.            move.l    fp_bit_alloc(a0),a1
  1114.            move.l    fp_sample(a0),a0
  1115.  
  1116.            move.w    d0,sub_band_limit    ; sblimit
  1117.            IFD    SKIP_UPPER_BAND
  1118.            cmp.w    sub_band_size,d0
  1119.            ble.s    ASM_II_deqnorm_0     ; sub_band_limit <= sub_band_size
  1120.            move.w    sub_band_size,sub_band_limit
  1121. ASM_II_deqnorm_0
  1122.            ENDC
  1123.            move.w    d1,channels         ; stereo ?
  1124.            mulu.w    #SBLIMIT,d2         ; x*SBLIMIT
  1125.            moveq.l    #MULT_FACTOR,d7
  1126.            moveq.l    #DEQUANT_FACTOR,d6
  1127.            lea.l    mult_table,a5
  1128.  
  1129. ASM_II_deqnorm_1
  1130.            movem.l    d2/a0-a4,-(sp)
  1131.            move.l    a0,a6             ; a6 = sample[k][0][0]
  1132.            lea.l    (a3,d2.w*4),a3       ; a3 = &scale_index[k][x][0]
  1133.            move.w    sub_band_limit,d0
  1134.            move.w    d0,sub_band_index
  1135.  
  1136.            lea.l    dequantize_II_table,a0
  1137. ASM_II_deqnorm_2
  1138.            subq.w    #1,sub_band_index
  1139.            bmi    ASM_II_deqnorm_7
  1140.  
  1141.            move.l    (a3)+,d0             ; d0 = *scale++
  1142.            move.l    (a1)+,d1             ; d1 = *bit_alloc++;
  1143.            beq    ASM_II_deqnorm_5     ; no bit allocated
  1144.  
  1145.            move.w    (a5,d0.w*2),d5       ; m = d5;
  1146.            move.l    (a4,d1.w*4),d0       ; d0 = alloc_table[i][d3]
  1147.            bfextu    d0{ALLOC_O_SHIFT:ALLOC_W_SHIFT},d2  ; d2 = shift
  1148.            bfextu    d0{ALLOC_O_QUANT:ALLOC_W_QUANT},d1  ; d1 = quant
  1149.  
  1150.            move.w    (a0,d1.w*4),d3       ; d
  1151.            move.w    (2,a0,d1.w*4),d4     ; c
  1152.            muls.w    d5,d4             ; c*m
  1153.            asr.l    d7,d4             ; >>MULT_FACTOR
  1154.  
  1155.            move.l    (a6),d0              ; sample[k][0][i]
  1156.            asl.l    d2,d0             ; left justify sample (normalize)
  1157.            bchg    #15,d0             ; Invert Msb of sample
  1158.            asr.w    #15-INT_FACTOR,d0
  1159.            add.w    d3,d0             ; d0 + d
  1160.            muls.w    d4,d0             ; * c*m
  1161.            asr.l    d6,d0             ; >>DEQUANT_FACTOR
  1162.            move.w    d0,(a2)              ; -> fraction[k][0][i]
  1163.  
  1164.            move.l    SBLIMIT*4(a6),d0     ; sample[k][1][i]
  1165.            asl.l    d2,d0             ; left justify sample (normalize)
  1166.            bchg    #15,d0             ; Invert Msb of sample
  1167.            asr.w    #15-INT_FACTOR,d0
  1168.            add.w    d3,d0             ; d0 + d
  1169.            muls.w    d4,d0             ; * c*m
  1170.            asr.l    d6,d0             ; >>DEQUANT_FACTOR
  1171.            move.w    d0,SBLIMIT*2(a2)     ; -> fraction[k][1][i]
  1172.  
  1173.            move.l    SBLIMIT*8(a6),d0     ; sample[k][2][i]
  1174.            asl.l    d2,d0             ; left justify sample (normalize)
  1175.            bchg    #15,d0             ; Invert Msb of sample
  1176.            asr.w    #15-INT_FACTOR,d0
  1177.            add.w    d3,d0             ; d0 + d
  1178.            muls.w    d4,d0             ; * c*m
  1179.            asr.l    d6,d0             ; >>DEQUANT_FACTOR
  1180.            move.w    d0,SBLIMIT*4(a2)     ; -> fraction[k][2][i]
  1181.  
  1182.            bra    ASM_II_deqnorm_6
  1183. ASM_II_deqnorm_5
  1184.            clr.w    (a2)                 ; fraction[k][0][i] = 0
  1185.            clr.w    SBLIMIT*2(a2)        ; fraction[k][1][i] = 0
  1186.            clr.w    SBLIMIT*4(a2)        ; fraction[k][2][i] = 0
  1187. ASM_II_deqnorm_6
  1188.            addq.l    #4,a6             ; -> sample ptr ++
  1189.            addq.l    #2,a2             ; -> fraction ptr ++
  1190.            add.l    #4*16,a4         ; next alloc_table ptr
  1191.  
  1192.            bra    ASM_II_deqnorm_2     ; next sub_band
  1193.  
  1194. ASM_II_deqnorm_7
  1195.            move.w    sub_band_limit,d0
  1196. ASM_II_deqnorm_8
  1197.            IFND    SKIP_UPPER_BAND      ; 08/05/1995
  1198.            cmp.w    #SBLIMIT,d0
  1199.            ELSE                 ; !!! incompatible with FILTER_?_SUM
  1200.            cmp.w    sub_band_size,d0
  1201.            ENDC
  1202.            bge    ASM_II_deqnorm_9
  1203.            clr.w    (a2)                 ; fraction[k][0][i] = 0
  1204.            clr.w    SBLIMIT*2(a2)        ; fraction[k][1][i] = 0
  1205.            clr.w    SBLIMIT*4(a2)        ; fraction[k][2][i] = 0
  1206.            addq.l    #2,a2             ; -> fraction ptr ++
  1207.            addq.w    #1,d0
  1208.            bra    ASM_II_deqnorm_8
  1209. ASM_II_deqnorm_9
  1210.            movem.l    (sp)+,d2/a0-a4
  1211.            subq.w    #1,channels
  1212.            ble    ASM_II_deqnorm_end
  1213.            add.l    #4*3*SBLIMIT,a0      ; next -> &sample[k][0][0]
  1214.            add.l    #4*SBLIMIT,a1         ; next -> &bit_alloc[k][0]
  1215.            add.l    #2*3*SBLIMIT,a2      ; next -> &fraction[k][0][0]
  1216.            add.l    #4*3*SBLIMIT,a3      ; next -> &scale_index[k][0][0]
  1217.            bra    ASM_II_deqnorm_1
  1218.  
  1219. ASM_II_deqnorm_end
  1220.            movem.l    (sp)+,d2-d7/a2-a6
  1221.            rts
  1222.  
  1223. ;           Apply the synthesis filter to a sub band
  1224. ;
  1225. ;           a0: bandPtr (=fraction)
  1226. ;           a1: out_filter_buffer
  1227. ;
  1228. @ASM_filter_band
  1229.            tst.w    quar_freq
  1230.            bne    fast_filter_quart
  1231.            tst.w    half_freq
  1232.            bne    fast_filter_half
  1233.            bra    fast_filter_full
  1234. ;
  1235. ;           Filter COS values for fast cosine transform
  1236. ;
  1237. COS1_64        equ    $8028
  1238. COS3_64        equ    $8167
  1239. COS5_64        equ    $83F4
  1240. COS7_64        equ    $87F2
  1241. COS9_64        equ    $8D98
  1242. COS11_64       equ    $953B
  1243. COS13_64       equ    $9F5C
  1244. COS15_64       equ    $ACC0
  1245. COS17_64       equ    $BE9A
  1246. COS19_64       equ    $D6E0
  1247. COS21_64       equ    $F8FA
  1248. COS23_64       equ    $12B60
  1249. COS25_64       equ    $17BF2
  1250. COS27_64       equ    $20ECB
  1251. COS29_64       equ    $36859
  1252. COS31_64       equ    $A30A4
  1253. COS1_32        equ    $809F
  1254. COS3_32        equ    $85C2
  1255. COS5_32        equ    $9123
  1256. COS7_32        equ    $A596
  1257. COS9_32        equ    $C9C5
  1258. COS11_32       equ    $10F89
  1259. COS13_32       equ    $1B8F2
  1260. COS15_32       equ    $519E5
  1261. COS1_16        equ    $8282
  1262. COS3_16        equ    $99F2
  1263. COS5_16        equ    $E665
  1264. COS7_16        equ    $2901B
  1265. COS1_8           equ    $8A8C
  1266. COS3_8           equ    $14E7B
  1267. COS1_4           equ    $B505
  1268.  
  1269.  
  1270. FF_MUL           MACRO
  1271.            move.l    (a2)+,d0
  1272.            sub.l    -(a3),d0
  1273.            muls.l    #\1,d1:d0
  1274.            move.w    d1,d0
  1275.            swap    d0
  1276.            move.l    d0,(a4)+
  1277.            ENDM
  1278.  
  1279. FF_ADD           MACRO
  1280.            move.l    \1*4(a2),d0
  1281.            add.l    \2*4(a2),d0
  1282.            move.l    d0,(a4)+
  1283.            ENDM
  1284.  
  1285. FF_SUB_MUL     MACRO
  1286.            move.l    \1*4(a2),d0
  1287.            sub.l    \2*4(a2),d0
  1288.            muls.l    \3,d4:d0
  1289.            move.w    d4,d0
  1290.            swap    d0
  1291.            move.l    d0,(a4)+
  1292.            ENDM
  1293.  
  1294. FFF_MUL        MACRO
  1295.            move.l    (a2)+,d0
  1296.            move.l    d0,d1
  1297.            move.l    -(a3),d2
  1298.            add.l    d2,d1
  1299.            move.l    d1,(a4)+
  1300.            sub.l    d2,d0
  1301.            muls.l    #\1,d1:d0
  1302.            move.w    d1,d0
  1303.            swap    d0
  1304.            move.l    d0,\2*4-4(a4)
  1305.            ENDM
  1306.  
  1307. fast_filter_sub
  1308.            move.l    a5,a2           ; @p(0)
  1309.            lea    16*4(a2),a3    ; @p(16)
  1310.            move.l    a6,a4           ; @pp(0)
  1311.  
  1312.            FFF_MUL    COS1_32,8      ; pp(i=0..7)  = p(i) + p(15-i)
  1313.            FFF_MUL    COS3_32,8      ; pp(i=8..15) = COSx*[p(i) - p(15-i)]
  1314.            FFF_MUL    COS5_32,8
  1315.            FFF_MUL    COS7_32,8
  1316.            FFF_MUL    COS9_32,8
  1317.            FFF_MUL    COS11_32,8
  1318.            FFF_MUL    COS13_32,8
  1319.            FFF_MUL    COS15_32,8
  1320.  
  1321.            move.l    a6,a2           ; @pp(0)
  1322.            lea    8*4(a2),a3     ; @pp(8)
  1323.            move.l    a5,a4           ; @p(0)
  1324.  
  1325.            FFF_MUL    COS1_16,4      ; p(i=0..3) = pp(i) + pp(7-i)
  1326.            FFF_MUL    COS3_16,4      ; p(i=4..7) = COSx*[pp(i) - pp(7-i)]
  1327.            FFF_MUL    COS5_16,4
  1328.            FFF_MUL    COS7_16,4
  1329.            lea    8*4(a6),a2     ; @pp(8)
  1330.            lea    8*4(a2),a3     ; @pp(16)
  1331.            lea    4*4(a4),a4     ; skip p(4)..p(7)
  1332.            FFF_MUL    COS1_16,4
  1333.            FFF_MUL    COS3_16,4
  1334.            FFF_MUL    COS5_16,4
  1335.            FFF_MUL    COS7_16,4
  1336.  
  1337.            move.l    a5,a2           ; @p(0)
  1338.            move.l    a6,a4           ; @pp(0)
  1339.  
  1340.            move.l    #COS1_8,d1
  1341.            move.l    #COS3_8,d2
  1342.            FF_ADD    0,3
  1343.            FF_ADD    1,2
  1344.            FF_SUB_MUL  0,3,d1
  1345.            FF_SUB_MUL  1,2,d2
  1346.            FF_ADD    4,7
  1347.            FF_ADD    5,6
  1348.            FF_SUB_MUL  4,7,d1
  1349.            FF_SUB_MUL  5,6,d2
  1350.            FF_ADD    8,11
  1351.            FF_ADD    9,10
  1352.            FF_SUB_MUL  8,11,d1
  1353.            FF_SUB_MUL  9,10,d2
  1354.            FF_ADD    12,15
  1355.            FF_ADD    13,14
  1356.            FF_SUB_MUL  12,15,d1
  1357.            FF_SUB_MUL  13,14,d2
  1358.  
  1359.            lea    filter_pp,a2      ; @pp(0)
  1360.            lea    filter_p,a4      ; @p(0)
  1361.            move.l    #COS1_4,d3
  1362.            moveq.w    #8-1,d7
  1363. fast_filter_s5
  1364.            move.l    (a2)+,d0
  1365.            move.l    d0,d2
  1366.            move.l    (a2)+,d1
  1367.            add.l    d1,d0
  1368.            move.l    d0,(a4)+
  1369.            sub.l    d1,d2
  1370.            muls.l    d3,d4:d2
  1371.            move.w    d4,d2
  1372.            swap    d2
  1373.            move.l    d2,(a4)+
  1374.            dbra    d7,fast_filter_s5
  1375.  
  1376.            rts
  1377.  
  1378. ;           Apply the FAST synthesis filter to a sub band
  1379. ;           Generate full frequency sample
  1380. ;
  1381. ;           a0: bandPtr (=fraction)
  1382. ;           a1: out_filter_buffer
  1383. ;
  1384. fast_filter_full
  1385.            movem.l    d2-d7/a2-a6,-(sp)
  1386.  
  1387.            lea    filter_p,a5
  1388.            lea    filter_pp,a6
  1389.  
  1390.            move.l    a0,a2           ; fraction(0)
  1391.            lea    32*2(a2),a3    ; fraction(32)
  1392.            move.l    a5,a4           ; @p(0)
  1393.  
  1394.            moveq.w    #16-1,d7
  1395. fast_filter_f1                   ; p(i=0..15) = f(i) + f(31-i)
  1396.            move.w    (a2)+,d0
  1397.            ext.l    d0
  1398.            move.w    -(a3),d1
  1399.            ext.l    d1
  1400.            add.l    d0,d1
  1401.            move.l    d1,(a4)+
  1402.            dbra    d7,fast_filter_f1
  1403.  
  1404.            bsr    fast_filter_sub
  1405.  
  1406.            move.l    a5,a2           ; @p(0)
  1407.  
  1408.            move.l    6*4(a2),d1
  1409.            add.l    7*4(a2),d1
  1410.            move.l    5*4(a2),d0
  1411.            add.l    d1,d0
  1412.            neg.l    d0
  1413.            move.w    d0,36*2(a1)       ; [36-17] => b(36)
  1414.            move.w    d0,60*2(a1)       ; [36-17] => b(60)
  1415.            move.l    4*4(a2),d0
  1416.            add.l    d1,d0
  1417.            neg.l    d0
  1418.            move.w    d0,44*2(a1)       ; [44-17] => b(44)
  1419.            move.w    d0,52*2(a1)       ; [44-17] => b(52)
  1420.            move.l    11*4(a2),d1
  1421.            add.l    15*4(a2),d1
  1422.            move.l    d1,d0
  1423.            move.w    d0,10*2(a1)       ; [10] => b(10)
  1424.            neg.l    d0
  1425.            move.w    d0,22*2(a1)       ; [10] => -b(22)
  1426.            move.l    13*4(a2),d0
  1427.            add.l    d1,d0
  1428.            move.w    d0,6*2(a1)        ; [6] => b(6)
  1429.            neg.l    d0
  1430.            move.w    d0,26*2(a1)       ; [6] => -b(26)
  1431.            move.l    14*4(a2),d1
  1432.            add.l    15*4(a2),d1
  1433.            move.l    8*4(a2),d0
  1434.            add.l    12*4(a2),d0
  1435.            add.l    d1,d0
  1436.            neg.l    d0
  1437.            move.w    d0,46*2(a1)       ; [46-17] => b(46)
  1438.            move.w    d0,50*2(a1)       ; [46-17] => b(50)
  1439.            move.l    9*4(a2),d0
  1440.            add.l    13*4(a2),d0
  1441.            add.l    d1,d0
  1442.            neg.l    d0
  1443.            move.w    d0,34*2(a1)       ; [34-17] => b(34)
  1444.            move.w    d0,62*2(a1)       ; [34-17] => b(62)
  1445.            add.l    10*4(a2),d1
  1446.            add.l    11*4(a2),d1
  1447.            move.l    13*4(a2),d0
  1448.            add.l    d1,d0
  1449.            neg.l    d0
  1450.            move.w    d0,38*2(a1)       ; [38-17] => b(38)
  1451.            move.w    d0,58*2(a1)       ; [38-17] => b(58)
  1452.            move.l    12*4(a2),d0
  1453.            add.l    d1,d0
  1454.            neg.l    d0
  1455.            move.w    d0,42*2(a1)       ; [42-17] => b(42)
  1456.            move.w    d0,54*2(a1)       ; [54-17] => b(54)
  1457.            move.l    9*4(a2),d0
  1458.            add.l    13*4(a2),d0
  1459.            add.l    15*4(a2),d0
  1460.            move.w    d0,2*2(a1)        ; [2] => b(2)
  1461.            neg.l    d0
  1462.            move.w    d0,30*2(a1)       ; [2] => -b(30)
  1463.            move.l    5*4(a2),d0
  1464.            add.l    7*4(a2),d0
  1465.            move.w    d0,4*2(a1)        ; [4] => b(4)
  1466.            neg.l    d0
  1467.            move.w    d0,28*2(a1)       ; [4] => -b(28)
  1468.            move.l    0*4(a2),d0
  1469.            neg.l    d0
  1470.            move.w    d0,48*2(a1)       ; [48-17] => b(48)
  1471.            move.l    1*4(a2),d0
  1472.            move.w    d0,0*2(a1)        ; [0] => b(0)
  1473.            neg.l    d0
  1474.            move.w    d0,32*2(a1)       ; [0] => -b(32)
  1475.            move.l    3*4(a2),d0
  1476.            move.w    d0,8*2(a1)        ; [8] => b(8)
  1477.            neg.l    d0
  1478.            move.w    d0,24*2(a1)       ; [8] => -b(24)
  1479.            move.l    7*4(a2),d0
  1480.            move.w    d0,12*2(a1)       ; [12] => b(12)
  1481.            neg.l    d0
  1482.            move.w    d0,20*2(a1)       ; [12] => -b(20)
  1483.            move.l    15*4(a2),d0
  1484.            move.w    d0,14*2(a1)       ; [14] => b(14)
  1485.            neg.l    d0
  1486.            move.w    d0,18*2(a1)       ; [14] => -b(18)
  1487.            move.l    2*4(a2),d0
  1488.            add.l    3*4(a2),d0
  1489.            neg.l    d0
  1490.            move.w    d0,40*2(a1)       ; [40-17] => b(40)
  1491.            move.w    d0,56*2(a1)       ; [40-17] => b(56)
  1492.  
  1493.            clr.w    16*2(a1)          ; 0 => b(16)
  1494.  
  1495.            move.l    a0,a2           ; fraction(0)
  1496.            lea    32*2(a2),a3    ; fraction(32)
  1497.            move.l    a5,a4           ; @p(0)
  1498.  
  1499.            lea    filter_cos64,a0
  1500.            moveq.w    #16-1,d7
  1501. fast_filter_f2                   ; p(i=0..15) = COSx*[f(i) - f(31-i)]
  1502.            move.w    (a2)+,d0
  1503.            ext.l    d0
  1504.            move.w    -(a3),d1
  1505.            ext.l    d1
  1506.            sub.l    d1,d0
  1507.            muls.l    (a0)+,d1:d0
  1508.            move.w    d1,d0
  1509.            swap    d0
  1510.            move.l    d0,(a4)+
  1511.            dbra    d7,fast_filter_f2
  1512.  
  1513.            bsr    fast_filter_sub
  1514.  
  1515.            move.l    a5,a2           ; @p(0)
  1516.  
  1517.            move.l    13*4(a2),d1
  1518.            add.l    15*4(a2),d1
  1519.            move.l    1*4(a2),d0
  1520.            add.l    9*4(a2),d0
  1521.            add.l    d1,d0
  1522.            move.w    d0,1*2(a1)        ; [1] => b(1)
  1523.            neg.l    d0
  1524.            move.w    d0,31*2(a1)       ; [1] => -b(31)
  1525.            move.l    5*4(a2),d0
  1526.            add.l    7*4(a2),d0
  1527.            add.l    11*4(a2),d0
  1528.            add.l    d1,d0
  1529.            move.w    d0,5*2(a1)        ; [5] => b(5)
  1530.            neg.l    d0
  1531.            move.w    d0,27*2(a1)       ; [5] => -b(27)
  1532.            add.l    9*4(a2),d1
  1533.            move.l    1*4(a2),d0
  1534.            add.l    14*4(a2),d0
  1535.            add.l    d1,d0
  1536.            neg.l    d0
  1537.            move.w    d0,33*2(a1)       ; [33-17] => b(33)
  1538.            move.w    d0,63*2(a1)       ; [33-17] => b(63)
  1539.            add.l    5*4(a2),d1
  1540.            add.l    7*4(a2),d1
  1541.            move.l    d1,d0
  1542.            move.w    d0,3*2(a1)        ; [3] => b(3)
  1543.            neg.l    d0
  1544.            move.w    d0,29*2(a1)       ; [3] => -b(29)
  1545.            move.l    6*4(a2),d0
  1546.            add.l    14*4(a2),d0
  1547.            add.l    d1,d0
  1548.            neg.l    d0
  1549.            move.w    d0,35*2(a1)       ; [35-17] => b(35)
  1550.            move.w    d0,61*2(a1)       ; [35-17] => b(61)
  1551.            move.l    10*4(a2),d1
  1552.            add.l    11*4(a2),d1
  1553.            add.l    14*4(a2),d1
  1554.            add.l    15*4(a2),d1
  1555.            move.l    2*4(a2),d0
  1556.            add.l    3*4(a2),d0
  1557.            add.l    13*4(a2),d0
  1558.            add.l    d1,d0
  1559.            neg.l    d0
  1560.            move.w    d0,39*2(a1)       ; [39-17] => b(39)
  1561.            move.w    d0,57*2(a1)       ; [39-17] => b(57)
  1562.            move.l    4*4(a2),d0
  1563.            add.l    6*4(a2),d0
  1564.            add.l    7*4(a2),d0
  1565.            add.l    12*4(a2),d0
  1566.            add.l    d1,d0
  1567.            neg.l    d0
  1568.            move.w    d0,43*2(a1)       ; [43-17] => b(43)
  1569.            move.w    d0,53*2(a1)       ; [43-17] => b(53)
  1570.            move.l    5*4(a2),d0
  1571.            add.l    6*4(a2),d0
  1572.            add.l    7*4(a2),d0
  1573.            add.l    13*4(a2),d0
  1574.            add.l    d1,d0
  1575.            neg.l    d0
  1576.            move.w    d0,37*2(a1)       ; [37-17] => b(37)
  1577.            move.w    d0,59*2(a1)       ; [37-17] => b(59)
  1578.            move.l    2*4(a2),d0
  1579.            add.l    3*4(a2),d0
  1580.            add.l    12*4(a2),d0
  1581.            add.l    d1,d0
  1582.            neg.l    d0
  1583.            move.w    d0,41*2(a1)       ; [41-17] => b(41)
  1584.            move.w    d0,55*2(a1)       ; [55-17] => b(55)
  1585.            move.l    8*4(a2),d1
  1586.            add.l    12*4(a2),d1
  1587.            add.l    14*4(a2),d1
  1588.            add.l    15*4(a2),d1
  1589.            move.l    0*4(a2),d0
  1590.            add.l    d1,d0
  1591.            neg.l    d0
  1592.            move.w    d0,47*2(a1)       ; [47-17] => b(47)
  1593.            move.w    d0,49*2(a1)       ; [47-17] => b(49)
  1594.            move.l    4*4(a2),d0
  1595.            add.l    6*4(a2),d0
  1596.            add.l    7*4(a2),d0
  1597.            add.l    d1,d0
  1598.            neg.l    d0
  1599.            move.w    d0,45*2(a1)       ; [45-17] => b(45)
  1600.            move.w    d0,51*2(a1)       ; [45-17] => b(51)
  1601.            move.l    11*4(a2),d1
  1602.            add.l    15*4(a2),d1
  1603.            move.l    7*4(a2),d0
  1604.            add.l    d1,d0
  1605.            move.w    d0,11*2(a1)       ; [11] => b(11)
  1606.            neg.l    d0
  1607.            move.w    d0,21*2(a1)       ; [11] => -b(21)
  1608.            add.l    3*4(a2),d1
  1609.            move.l    d1,d0
  1610.            move.w    d0,9*2(a1)        ; [9] => b(9)
  1611.            neg.l    d0
  1612.            move.w    d0,23*2(a1)       ; [9] => -b(23)
  1613.            move.l    13*4(a2),d0
  1614.            add.l    d1,d0
  1615.            move.w    d0,7*2(a1)        ; [7] => b(7)
  1616.            neg.l    d0
  1617.            move.w    d0,25*2(a1)       ; [7] => -b(25)
  1618.            move.l    7*4(a2),d0
  1619.            add.l    15*4(a2),d0
  1620.            move.w    d0,13*2(a1)       ; [13] => b(13)
  1621.            neg.l    d0
  1622.            move.w    d0,19*2(a1)       ; [13] => -b(19)
  1623.            move.l    15*4(a2),d0
  1624.            move.w    d0,15*2(a1)       ; [15] => b(15)
  1625.            neg.l    d0
  1626.            move.w    d0,17*2(a1)       ; [15] => -b(17)
  1627.  
  1628.            movem.l    (sp)+,d2-d7/a2-a6
  1629.            rts
  1630.  
  1631.  
  1632.  
  1633. FFH_MUL        MACRO
  1634.            move.w    (a2)+,d0
  1635.            ext.l    d0
  1636.            move.l    d0,d1
  1637.            move.w    -(a3),d2
  1638.            ext.l    d2
  1639.            add.l    d2,d1
  1640.            move.l    d1,(a4)+
  1641.            sub.l    d2,d0
  1642.            muls.l    #\1,d1:d0
  1643.            move.w    d1,d0
  1644.            swap    d0
  1645.            move.l    d0,7*4(a4)
  1646.            ENDM
  1647.  
  1648. fast_filter_half
  1649.            movem.l    d2-d7/a2-a6,-(sp)
  1650.  
  1651.            move.l    a0,a2           ; fraction(0)
  1652.            lea    16*2(a2),a3    ; fraction(16)
  1653.  
  1654.            lea    filter_pp,a4   ; @pp(0)
  1655.  
  1656.            FFH_MUL    COS1_32        ; pp(i=0..7)  = f(i) + f(15-i)
  1657.            FFH_MUL    COS3_32        ; pp(i=8..15) = COSx*[f(i) - f(15-i)]
  1658.            FFH_MUL    COS5_32
  1659.            FFH_MUL    COS7_32
  1660.            FFH_MUL    COS9_32
  1661.            FFH_MUL    COS11_32
  1662.            FFH_MUL    COS13_32
  1663.            FFH_MUL    COS15_32
  1664.  
  1665.            lea    filter_pp,a2  ; @pp(0)
  1666.            lea    8*4(a2),a3    ; @pp(8)
  1667.            lea    filter_p,a4   ; @p(0)
  1668.            moveq.w    #4-1,d7
  1669. fast_filter_h3                  ; p(i=0..3) = pp(i) + p(7-i)
  1670.            move.l    (a2)+,d0
  1671.            add.l    -(a3),d0
  1672.            move.l    d0,(a4)+
  1673.            dbra    d7,fast_filter_h3
  1674.  
  1675.            lea    filter_pp,a2  ; @pp(0)
  1676.            lea    8*4(a2),a3    ; @pp(8)
  1677.  
  1678.            FF_MUL    COS1_16 ; p(i=4..7) = COSx*[p(i) - p(7-i)]
  1679.            FF_MUL    COS3_16
  1680.            FF_MUL    COS5_16
  1681.            FF_MUL    COS7_16
  1682.  
  1683.            lea    filter_pp+8*4,a2  ; @pp(8)
  1684.            lea    8*4(a2),a3        ; @pp(16)
  1685.            moveq.w    #4-1,d7
  1686. fast_filter_h4             ; p(i=8..11) = pp(i) + p(15-i+8)
  1687.            move.l    (a2)+,d0
  1688.            add.l    -(a3),d0
  1689.            move.l    d0,(a4)+
  1690.            dbra    d7,fast_filter_h4
  1691.  
  1692.            lea    filter_pp+8*4,a2  ; @pp(8)
  1693.            lea    8*4(a2),a3        ; @pp(16)
  1694.  
  1695.            FF_MUL    COS1_16 ; p(i=12..15) = COSx*[p(i) - p(15-i+8)]
  1696.            FF_MUL    COS3_16
  1697.            FF_MUL    COS5_16
  1698.            FF_MUL    COS7_16
  1699.  
  1700.            lea    filter_p,a2      ; @p(0)
  1701.            lea    filter_pp,a4      ; @pp(0)
  1702.  
  1703.            move.l    #COS1_8,d1
  1704.            move.l    #COS3_8,d2
  1705.            FF_ADD    0,3
  1706.            FF_ADD    1,2
  1707.            FF_SUB_MUL  0,3,d1
  1708.            FF_SUB_MUL  1,2,d2
  1709.            FF_ADD    4,7
  1710.            FF_ADD    5,6
  1711.            FF_SUB_MUL  4,7,d1
  1712.            FF_SUB_MUL  5,6,d2
  1713.            FF_ADD    8,11
  1714.            FF_ADD    9,10
  1715.            FF_SUB_MUL  8,11,d1
  1716.            FF_SUB_MUL  9,10,d2
  1717.            FF_ADD    12,15
  1718.            FF_ADD    13,14
  1719.            FF_SUB_MUL  12,15,d1
  1720.            FF_SUB_MUL  13,14,d2
  1721.  
  1722.            lea    filter_pp,a2      ; @pp(0)
  1723.            lea    filter_p,a4      ; @p(0)
  1724.            move.l    #COS1_4,d3
  1725.            moveq.w    #8-1,d7
  1726. fast_filter_h5
  1727.            move.l    (a2)+,d0
  1728.            move.l    d0,d2
  1729.            move.l    (a2)+,d1
  1730.            add.l    d1,d0
  1731.            move.l    d0,(a4)+
  1732.            sub.l    d1,d2
  1733.            muls.l    d3,d4:d2
  1734.            move.w    d4,d2
  1735.            swap    d2
  1736.            move.l    d2,(a4)+
  1737.            dbra    d7,fast_filter_h5
  1738.  
  1739.            lea    filter_p,a2      ; @p(0)
  1740.  
  1741.            move.l    6*4(a2),d1
  1742.            add.l    7*4(a2),d1
  1743.            move.l    5*4(a2),d0
  1744.            add.l    d1,d0
  1745.            neg.l    d0
  1746.            move.w    d0,36*2(a1)       ; [36-17] => b(36)
  1747.            move.w    d0,60*2(a1)       ; [36-17] => b(60)
  1748.            move.l    4*4(a2),d0
  1749.            add.l    d1,d0
  1750.            neg.l    d0
  1751.            move.w    d0,44*2(a1)       ; [44-17] => b(44)
  1752.            move.w    d0,52*2(a1)       ; [44-17] => b(52)
  1753.            move.l    11*4(a2),d1
  1754.            add.l    15*4(a2),d1
  1755.            move.l    d1,d0
  1756.            move.w    d0,10*2(a1)       ; [10] => b(10)
  1757.            neg.l    d0
  1758.            move.w    d0,22*2(a1)       ; [10] => -b(22)
  1759.            move.l    13*4(a2),d0
  1760.            add.l    d1,d0
  1761.            move.w    d0,6*2(a1)        ; [6] => b(6)
  1762.            neg.l    d0
  1763.            move.w    d0,26*2(a1)       ; [6] => -b(26)
  1764.            move.l    14*4(a2),d1
  1765.            add.l    15*4(a2),d1
  1766.            move.l    8*4(a2),d0
  1767.            add.l    12*4(a2),d0
  1768.            add.l    d1,d0
  1769.            neg.l    d0
  1770.            move.w    d0,46*2(a1)       ; [46-17] => b(46)
  1771.            move.w    d0,50*2(a1)       ; [46-17] => b(50)
  1772.            move.l    9*4(a2),d0
  1773.            add.l    13*4(a2),d0
  1774.            add.l    d1,d0
  1775.            neg.l    d0
  1776.            move.w    d0,34*2(a1)       ; [34-17] => b(34)
  1777.            move.w    d0,62*2(a1)       ; [34-17] => b(62)
  1778.            add.l    10*4(a2),d1
  1779.            add.l    11*4(a2),d1
  1780.            move.l    13*4(a2),d0
  1781.            add.l    d1,d0
  1782.            neg.l    d0
  1783.            move.w    d0,38*2(a1)       ; [38-17] => b(38)
  1784.            move.w    d0,58*2(a1)       ; [38-17] => b(58)
  1785.            move.l    12*4(a2),d0
  1786.            add.l    d1,d0
  1787.            neg.l    d0
  1788.            move.w    d0,42*2(a1)       ; [42-17] => b(42)
  1789.            move.w    d0,54*2(a1)       ; [54-17] => b(54)
  1790.            move.l    9*4(a2),d0
  1791.            add.l    13*4(a2),d0
  1792.            add.l    15*4(a2),d0
  1793.            move.w    d0,2*2(a1)        ; [2] => b(2)
  1794.            neg.l    d0
  1795.            move.w    d0,30*2(a1)       ; [2] => -b(30)
  1796.            move.l    5*4(a2),d0
  1797.            add.l    7*4(a2),d0
  1798.            move.w    d0,4*2(a1)        ; [4] => b(4)
  1799.            neg.l    d0
  1800.            move.w    d0,28*2(a1)       ; [4] => -b(28)
  1801.            move.l    0*4(a2),d0
  1802.            neg.l    d0
  1803.            move.w    d0,48*2(a1)       ; [48-17] => b(48)
  1804.            move.l    1*4(a2),d0
  1805.            move.w    d0,0*2(a1)        ; [0] => b(0)
  1806.            neg.l    d0
  1807.            move.w    d0,32*2(a1)       ; [0] => -b(32)
  1808.            move.l    3*4(a2),d0
  1809.            move.w    d0,8*2(a1)        ; [8] => b(8)
  1810.            neg.l    d0
  1811.            move.w    d0,24*2(a1)       ; [8] => -b(24)
  1812.            move.l    7*4(a2),d0
  1813.            move.w    d0,12*2(a1)       ; [12] => b(12)
  1814.            neg.l    d0
  1815.            move.w    d0,20*2(a1)       ; [12] => -b(20)
  1816.            move.l    15*4(a2),d0
  1817.            move.w    d0,14*2(a1)       ; [14] => b(14)
  1818.            neg.l    d0
  1819.            move.w    d0,18*2(a1)       ; [14] => -b(18)
  1820.            move.l    2*4(a2),d0
  1821.            add.l    3*4(a2),d0
  1822.            neg.l    d0
  1823.            move.w    d0,40*2(a1)       ; [40-17] => b(40)
  1824.            move.w    d0,56*2(a1)       ; [40-17] => b(56)
  1825.  
  1826.            clr.w    16*2(a1)          ; 0 => b(16)
  1827.  
  1828.            movem.l    (sp)+,d2-d7/a2-a6
  1829.            rts
  1830.  
  1831.  
  1832. FFQ_MUL        MACRO
  1833.            move.w    (a2)+,d0
  1834.            ext.l    d0
  1835.            move.l    d0,d1
  1836.            move.w    -(a3),d2
  1837.            ext.l    d2
  1838.            add.l    d2,d1
  1839.            move.l    d1,(a4)+
  1840.            sub.l    d2,d0
  1841.            muls.l    #\1,d1:d0
  1842.            move.w    d1,d0
  1843.            swap    d0
  1844.            move.l    d0,3*4(a4)
  1845.            ENDM
  1846.  
  1847. FFQ_MUL2       MACRO
  1848.            movem.l    (a2)+,d0-d3
  1849.            move.l    d0,d4
  1850.            add.l    d3,d4
  1851.            move.l    d4,(a4)+
  1852.            move.l    d0,d4
  1853.            sub.l    d3,d4
  1854.            muls.l    \1,d5:d4
  1855.            move.w    d5,d4
  1856.            swap    d4
  1857.            move.l    d4,4(a4)
  1858.            move.l    d1,d4
  1859.            add.l    d2,d4
  1860.            move.l    d4,(a4)+
  1861.            move.l    d1,d4
  1862.            sub.l    d2,d4
  1863.            muls.l    \2,d5:d4
  1864.            move.w    d5,d4
  1865.            swap    d4
  1866.            move.l    d4,4(a4)
  1867.            ENDM
  1868.  
  1869.  
  1870. ;           Apply the FAST synthesis filter to a sub band
  1871. ;           Generate 1/4 frequency sample
  1872. ;
  1873. ;           a0: bandPtr (=fraction)
  1874. ;           a1: out_filter_buffer
  1875. ;
  1876. fast_filter_quart
  1877.            movem.l    d2-d7/a2-a6,-(sp)
  1878.  
  1879.            lea    filter_p,a5
  1880.            lea    filter_pp,a6
  1881.  
  1882.            move.l    a0,a2           ; fraction(0)
  1883.            lea    8*2(a2),a3     ; fraction(8)
  1884.            move.l    a5,a4           ; @p(0)
  1885.  
  1886.                        ; p(i=0..3) = x(i) + x(7-i)
  1887.            FFQ_MUL    COS1_16        ; p(i=4..7) = COSx*[x(i) - x(7-i)]
  1888.            FFQ_MUL    COS3_16
  1889.            FFQ_MUL    COS5_16
  1890.            FFQ_MUL    COS7_16
  1891.  
  1892.            move.l    a5,a2           ; @p(0)
  1893.            move.l    a6,a4           ; @pp(0)
  1894.  
  1895.            IFD    FF_ADD
  1896.            move.l    #COS1_8,d1
  1897.            move.l    #COS3_8,d2
  1898.            FF_ADD    0,3
  1899.            FF_ADD    1,2
  1900.            FF_SUB_MUL  0,3,d1
  1901.            FF_SUB_MUL  1,2,d2
  1902.            FF_ADD    4,7
  1903.            FF_ADD    5,6
  1904.            FF_SUB_MUL  4,7,d1
  1905.            FF_SUB_MUL  5,6,d2
  1906.            ELSE
  1907.            move.l    #COS1_8,d6
  1908.            move.l    #COS3_8,d7
  1909.            FFQ_MUL2 d6,d7
  1910.            addq.l    #4*2,a4
  1911.            FFQ_MUL2 d6,d7
  1912.            ENDC
  1913.  
  1914.            move.l    a6,a2          ; @pp(0)
  1915.            move.l    a5,a4          ; @p(0)
  1916.            move.l    #COS1_4,d3
  1917.            moveq.w    #4-1,d7
  1918. fast_filter_q5
  1919.            move.l    (a2)+,d0
  1920.            move.l    d0,d2
  1921.            move.l    (a2)+,d1
  1922.            add.l    d1,d0
  1923.            move.l    d0,(a4)+
  1924.            sub.l    d1,d2
  1925.            muls.l    d3,d4:d2
  1926.            move.w    d4,d2
  1927.            swap    d2
  1928.            move.l    d2,(a4)+
  1929.            dbra    d7,fast_filter_q5
  1930.  
  1931.            move.l    a5,a2          ; @p(0)
  1932.  
  1933.            move.l    6*4(a2),d1
  1934.            add.l    7*4(a2),d1
  1935.            move.l    5*4(a2),d0
  1936.            add.l    d1,d0
  1937.            neg.l    d0
  1938.            move.w    d0,36*2(a1)       ; [36-17] => b(36)
  1939.            move.w    d0,60*2(a1)       ; [36-17] => b(60)
  1940.            move.l    4*4(a2),d0
  1941.            add.l    d1,d0
  1942.            neg.l    d0
  1943.            move.w    d0,44*2(a1)       ; [44-17] => b(44)
  1944.            move.w    d0,52*2(a1)       ; [44-17] => b(52)
  1945.            move.l    5*4(a2),d0
  1946.            add.l    7*4(a2),d0
  1947.            move.w    d0,4*2(a1)        ; [4] => b(4)
  1948.            neg.l    d0
  1949.            move.w    d0,28*2(a1)       ; [4] => -b(28)
  1950.            move.l    0*4(a2),d0
  1951.            neg.l    d0
  1952.            move.w    d0,48*2(a1)       ; [48-17] => b(48)
  1953.            move.l    1*4(a2),d0
  1954.            move.w    d0,0*2(a1)        ; [0] => b(0)
  1955.            neg.l    d0
  1956.            move.w    d0,32*2(a1)       ; [0] => -b(32)
  1957.            move.l    3*4(a2),d0
  1958.            move.w    d0,8*2(a1)        ; [8] => b(8)
  1959.            neg.l    d0
  1960.            move.w    d0,24*2(a1)       ; [8] => -b(24)
  1961.            move.l    7*4(a2),d0
  1962.            move.w    d0,12*2(a1)       ; [12] => b(12)
  1963.            neg.l    d0
  1964.            move.w    d0,20*2(a1)       ; [12] => -b(20)
  1965.            move.l    2*4(a2),d0
  1966.            add.l    3*4(a2),d0
  1967.            neg.l    d0
  1968.            move.w    d0,40*2(a1)       ; [40-17] => b(40)
  1969.            move.w    d0,56*2(a1)       ; [40-17] => b(56)
  1970.  
  1971.            clr.w    16*2(a1)          ; 0 => b(16)
  1972.  
  1973.            movem.l    (sp)+,d2-d7/a2-a6
  1974.            rts
  1975.  
  1976.  
  1977.            section    ASMDATA,data
  1978.            CNOP    0,4
  1979.  
  1980. filter_cos64   dc.l    COS1_64, COS3_64, COS5_64, COS7_64
  1981.            dc.l    COS9_64, COS11_64, COS13_64, COS15_64
  1982.            dc.l    COS17_64, COS19_64, COS21_64, COS23_64
  1983.            dc.l    COS25_64, COS27_64, COS29_64, COS31_64
  1984.  
  1985.            section    ASMVARS,bss
  1986.            CNOP    0,4
  1987.  
  1988. filter_p       ds.l    16
  1989. filter_pp      ds.l    16
  1990.  
  1991.            section    ASMCODE,code
  1992.  
  1993.  
  1994. ;WINDOW_CLIP    equ     1
  1995. ;WINDOW_HARD    equ     1
  1996.  
  1997. ;
  1998. ;           Window a sub band filtered sample
  1999. ;
  2000. ;           a0: out_filter_buffer
  2001. ;           a1: out_sample_buffer
  2002. ;           d0: buffer offset
  2003. ;           -> a1 = out_sample_buffer + out_sample_length
  2004. @ASM_window_band
  2005.  
  2006.            movem.l    d2-d7/a2-a6,-(sp)
  2007.  
  2008.            move.l    a1,a2
  2009.            moveq.l    #4,d7             ; Band skip for quarter
  2010.            tst.w    quar_freq
  2011.            beq.s    ASM_window_band0
  2012.            moveq.l    #2,d7             ; Band skip for half
  2013.            tst.w    half_freq
  2014.            beq.s    ASM_window_band0
  2015.            moveq.l    #1,d7             ; Band skip for normal
  2016. ASM_window_band0
  2017.            moveq.l    #WINDOW_FACTOR+INT_FACTOR-15,d7
  2018.            add.w    output_8bits,d7      ; add right shift value
  2019.            move.w    #$3FF,d2
  2020.            lea.l    window_table,a1
  2021.            lea.l    32*2*2,a4
  2022.            lea.l    32,a5
  2023.            lea.l    96,a6
  2024.            move.w    window_start,d6
  2025.            ext.l    d6
  2026.            add.w    d6,d0             ; add window offset to d0 (buffer offset)
  2027.            add.l    d6,a1             ; add window offset to window ptr
  2028.  
  2029.            moveq.l    #0,d6             ; d6 = j
  2030.            tst.w    output_8bits
  2031.            bne    window_band_5         ; 8 bit output selected
  2032. window_band_1
  2033.            clr.l    d1             ; d1 = sum
  2034.            lea.l    (a1,d6.w*2),a3       ; a3 = window[ k(=j) ]
  2035.            move.w    d6,d3
  2036.            add.w    d0,d3             ; d3 = l = j + buf_offset
  2037.            move.w    window_coeff,d5      ; d5 = (#-1)/2 coeffs
  2038. window_band_2
  2039.            and.w    d2,d3             ; l &= 0x3FF
  2040.            move.w    (a0,d3.w*2),d4       ; bufPtr[ l ] -> d4
  2041.            muls.w    (a3),d4              ; window[ k ] * bufPtr[ l ] -> d4
  2042.            add.l    d4,d1             ; sum += d4
  2043.            add.w    a6,d3             ; l += 96
  2044.            and.w    d2,d3             ; l &= 0x3FF
  2045.            move.w    (a0,d3.w*2),d4       ; bufPtr[ l ] -> d4
  2046.            muls.w    64(a3),d4            ; window[ k ] * bufPtr[ l ] -> d4
  2047.            add.l    a4,a3             ; a3 += 64
  2048.            add.l    d4,d1             ; sum += d4
  2049.            add.w    a5,d3             ; l += 32
  2050.            dbra    d5,window_band_2
  2051.            asr.l    d7,d1             ; sum >>= (WINDOW_FACTOR+INT_FACTOR-15)
  2052.  
  2053.            cmp.l    #-32768,d1
  2054.            blt    window_band_4l
  2055.            cmp.l    #32767,d1
  2056.            bgt    window_band_4h
  2057. window_band_4n
  2058.            move.w    d1,(a2)+
  2059.            add.w    window_skip,d6           ; next band
  2060.            cmp.w    a5,d6               ; equiv cmp.w #32,d6
  2061.            blt    window_band_1
  2062.            bra    window_band_9
  2063. window_band_4l move.l    #-32768,d1
  2064.            bra.s    window_band_4n
  2065. window_band_4h move.l    #32767,d1
  2066.            bra.s    window_band_4n
  2067.  
  2068. window_band_5
  2069.            clr.l    d1             ; d1 = sum
  2070.            lea.l    (a1,d6.w*2),a3       ; a3 = window[ k(=j) ]
  2071.            move.w    d6,d3
  2072.            add.w    d0,d3             ; d3 = l = j + buf_offset
  2073.            move.w    window_coeff,d5      ; d5 = (#-1)/2 coeffs
  2074. window_band_6
  2075.            and.w    d2,d3             ; l &= 0x3FF
  2076.            move.w    (a0,d3.w*2),d4       ; bufPtr[ l ] -> d4
  2077.            muls.w    (a3),d4              ; window[ k ] * bufPtr[ l ] -> d4
  2078.            add.l    d4,d1             ; sum += d4
  2079.            add.w    a6,d3             ; l += 96
  2080.            and.w    d2,d3             ; l &= 0x3FF
  2081.            move.w    (a0,d3.w*2),d4       ; bufPtr[ l ] -> d4
  2082.            muls.w    64(a3),d4            ; window[ k ] * bufPtr[ l ] -> d4
  2083.            add.l    a4,a3             ; a3 += 64
  2084.            add.l    d4,d1             ; sum += d4
  2085.            add.w    a5,d3             ; l += 32
  2086.            dbra    d5,window_band_6
  2087.            asr.l    d7,d1             ; sum >>= (WINDOW_FACTOR+INT_FACTOR-15)
  2088.  
  2089.            cmp.w    #-128,d1
  2090.            bge.s    window_band_71
  2091.            moveq.b    #-128,d1
  2092.            bra.s    window_band_72
  2093. window_band_71
  2094.            cmp.w    #127,d1
  2095.            ble.s    window_band_72
  2096.            moveq.b    #127,d1
  2097. window_band_72
  2098.            move.b    d1,(a2)+
  2099.            add.w    window_skip,d6           ; next band
  2100.            cmp.w    a5,d6               ; equiv cmp.w #32,d6
  2101.            blt    window_band_5
  2102. window_band_9
  2103.            move.l    a2,a1
  2104.            movem.l    (sp)+,d2-d7/a2-a6
  2105.            rts
  2106.  
  2107.  
  2108. ;           Sub band synthesis
  2109. ;
  2110. ;           a0:   frame_params *fr_ps
  2111. ;           d0:   int band_count
  2112. ;
  2113. @ASM_sub_band_synthesis
  2114.            movem.l    d2-d6/a2-a6,-(sp)
  2115.  
  2116.            move.l    a0,a2          ; a2 = frame_params
  2117.            move.l    d0,d4
  2118.            subq.l    #1,d4          ; d4 = band_count-1
  2119.            move.l    fp_stereo(a2),d5
  2120.            subq.l    #1,d5          ; d5 = #channels-1
  2121.            clr.l    d6          ; d6 = channel
  2122.            lea    fp_out_buffer(a2),a6 ; a6 = &sample[ 0 ]
  2123. sub_band_synthesis_0
  2124.            move.l    (a6),a5           ; a5 = sample[channel]
  2125.            move.l    fp_fraction(a2),a3
  2126.            move.l    d6,d1
  2127.            mulu.w    #2*3*SBLIMIT,d1
  2128.            add.l    d1,a3          ; a3 = fraction[channel]
  2129.            lea.l    filter_buffer,a4
  2130.            move.w    d6,d2
  2131.            mulu.w    #2*2*HAN_SIZE,d2
  2132.            add.l    d2,a4          ; -> a4 = &filter_buffer[channel][0]
  2133.            move.w    d4,d3
  2134. sub_band_synthesis_1
  2135.            lea.l    band_offset,a1
  2136.            move.w    (a1,d6.w*2),d2
  2137.            sub.w    #64,d2
  2138.            and.w    #$3FF,d2      ; d2 = (band_offset[k] - 64) & 0x3ff;
  2139.            move.w    d2,(a1,d6.w*2)
  2140.            lea.l    (a4,d2.w*2),a1    ; a1 = &filter_buffer[k][d2]
  2141.            move.l    a3,a0          ; a0 = &bandPtr[k][j][0]
  2142.            bsr    @ASM_filter_band
  2143.  
  2144.            move.l    a5,a1          ; a1 = &samples[k][j][0]
  2145.            move.l    a4,a0          ; a0 = &filter_buffer[k][0]
  2146.            move.l    d2,d0          ; d0 = band_offset[k]
  2147.            bsr    @ASM_window_band
  2148.  
  2149.            add.l    #2*SBLIMIT,a3      ; -> a3 = &bandPtr[k][j+1][0]
  2150.            move.l    a1,a5          ; a5 = next sample ptr
  2151.  
  2152.            dbra    d3,sub_band_synthesis_1 ; j++
  2153.  
  2154.            move.l    a5,(a6)           ; a5 = sample[channel]
  2155.            addq.l    #1,d6
  2156.            addq.l    #4,a6
  2157.  
  2158.            dbra    d5,sub_band_synthesis_0 ; next channel
  2159.  
  2160.            movem.l    (sp)+,d2-d6/a2-a6
  2161.            rts
  2162.  
  2163.  
  2164. ;
  2165. ;           Decode an audio MPEG I Layer I frame
  2166. ;
  2167. ;           a0:   frame_params *fr_ps
  2168. ;
  2169. @ASM_I_decode_frame
  2170.            movem.l    d2/a2,-(sp)
  2171.            move.l    a0,a2
  2172.            clr.l    d2
  2173. ASM_I_decode_frame_1
  2174.            move.l    a2,a0
  2175.            bsr    @ASM_I_buffer_sample
  2176.            move.l    a2,a0
  2177.            bsr    @ASM_I_deqnorm
  2178.            move.l    a2,a0
  2179.            moveq.l    #1,d0
  2180.            bsr    @ASM_sub_band_synthesis
  2181.            addq.l    #1,d2
  2182.            cmp.w    #SCALE_BLOCK,d2
  2183.            blt    ASM_I_decode_frame_1
  2184.  
  2185.            movem.l    (sp)+,d2/a2
  2186.            rts
  2187.  
  2188. ;
  2189. ;           Decode an audio MPEG I Layer II frame
  2190. ;
  2191. ;           a0:   frame_params *fr_ps
  2192. ;
  2193. @ASM_II_decode_frame
  2194.            movem.l    d2/a2,-(sp)
  2195.            move.l    a0,a2
  2196.            clr.l    d2
  2197. ASM_II_decode_frame_1
  2198.            move.l    a2,a0
  2199.            bsr    @ASM_II_buffer_sample
  2200.            move.l    a2,a0
  2201.            move.l    d2,d0
  2202.            lsr.l    #2,d0
  2203.            bsr    @ASM_II_deqnorm
  2204.            move.l    a2,a0
  2205.            moveq.l    #3,d0
  2206.            bsr    @ASM_sub_band_synthesis
  2207.            addq.l    #1,d2
  2208.            cmp.w    #SCALE_BLOCK,d2
  2209.            blt    ASM_II_decode_frame_1
  2210.  
  2211.            movem.l    (sp)+,d2/a2
  2212.            rts
  2213.  
  2214.            section    ASMDATA,data
  2215.            even
  2216.  
  2217. band_offset    dc.w    64,64
  2218.  
  2219.            section    ASMVARS,bss
  2220.            even
  2221.  
  2222. bsamp_sblimit  ds.w    1
  2223. bsamp_jsbound  ds.w    1
  2224. bsamp_channels ds.w    1
  2225.  
  2226. channels       ds.w    1
  2227. sub_band_limit ds.w    1
  2228. sub_band_index ds.w    1
  2229.  
  2230. sub_band_size  ds.w    1
  2231. output_8bits   ds.w    1          ; 0 if 16 bits output
  2232.                       ; > 0 if 8 bits output = right shift
  2233. half_freq      ds.w    1          ; = 0 if full freq output
  2234. quar_freq      ds.w    1          ; != 0 if quarter freq output
  2235.  
  2236. window_start   ds.w    1          ; start offset for windowing
  2237. window_coeff   ds.w    1          ; #coeff used for windowing
  2238. window_skip    ds.w    1          ; #values skipped (1=full,2=half,4=quart)
  2239.  
  2240. quality        ds.w    1
  2241.  
  2242.            even
  2243.  
  2244. band_buffer    ds.w    32
  2245.  
  2246. h_band_input   ds.w    16
  2247. h_band_buffer  ds.w    16
  2248. h_band_buffer2 ds.w    4+8+4+8
  2249.  
  2250. q_band_input   ds.w    8
  2251. q_band_buffer  ds.w    8
  2252. q_band_buffer2 ds.w    2+4+2+4
  2253.  
  2254.  
  2255. filter_buffer  ds.w    2*2*HAN_SIZE
  2256.  
  2257.  
  2258.